How to re-use existing CMake variables with new ge

2019-07-27 22:48发布

问题:

I need to build OpenCV for both 32-bit and 64-bit in VS2015.

I'm aware that I need a separate build tree for each generator.

OpenCV's CMake configuration has approximately 300 user-configurable variables, which I have finally got set to my satisfaction. Now I want to use the exact same set of decisions to build the 64-bit version.

Is there a way to transfer the variable values that represent my decisions to the new build tree? (Other than opening two CMake-GUIs side by side and checking that all ~300 values correspond.)

BTW, if the generator is changed, CMakeCache.txt must be deleted, according to the CMake mailing list [ http://cmake.3232098.n2.nabble.com/Changing-the-the-current-generator-in-CMake-GUI-td7587876.html ]. Manually editing it is very risky and will likely lead to undefined behaviour.

Thanks

回答1:

Turning my comment into an answer

You can use a partial CMakeCache.txt in the new directory (CMake will just pre-load the values that are there and reevaluate the rest).

So you can use a grep like approach and do

findstr "OpenCV_" CMakeCache.txt > \My\New\Path\CMakeCache.txt

Just tested it and seems to work as expected.

Reference

  • What are good grep tools for Windows?


标签: opencv cmake