0

Sorry for the vague title, I'm not sure how to phrase this correctly. I would like to write a cmake script that allows to build a target with different settings for bit width (forced 32 bit, forced 64 bit or native bit width) and static linking. I figured out how to set up the build under each condition and so far I'm using cmake options to switch between different setups.

My problem is that changing one of these build options with ccmake or on the command line also requires to look for new library paths. Since these paths are cached, I currently have to delete the cache when changing bit width. This way users also loose all other settings for options that are independent of bit width and static linking.

Is there a common way to handle this?

Flogo
  • 1,673
  • 4
  • 20
  • 33
  • 3
    I think maintaining separate build folders is the common way to handle this, so once you choose the bit-width for a given build, you don't allow it to be changed. – Fraser Oct 25 '14 at 10:45
  • Thanks. Would that mean I need one build folder for each combination of bit width, static/dynamic, and build mode (release, debug, ...)? – Flogo Oct 25 '14 at 10:50
  • 2
    `of bit width` yes, `static/dynamic` yes, `build mode (release, debug, ...` it [depends](http://stackoverflow.com/questions/24460486/cmake-build-type-not-being-used-in-cmakelists-txt/24470998#24470998) –  Oct 25 '14 at 12:34
  • Do you want to turn your comment into an answer so I can accept it? – Flogo Oct 26 '14 at 11:42

1 Answers1

1

Use different build directories for different settings:

  • cmake -H. -B_builds/arch64 -DCMAKE_CXX_FLAGS=-m64
  • cmake -H. -B_builds/arch32 -DCMAKE_CXX_FLAGS=-m32
  • cmake -H. -B_builds/shared -DBUILD_SHARED_LIBS=ON
  • cmake -H. -B_builds/static -DBUILD_SHARED_LIBS=OFF
  • cmake -H. -B_builds/debug -DCMAKE_BUILD_TYPE=Debug
  • cmake -H. -B_builds/release -DCMAKE_BUILD_TYPE=Release

Exceptions

Note that in each case there may be exceptions, like:

add_library(foo STATIC ${FOO_SOURCES}) # BUILD_SHARED_LIBS will be ignored

or for Visual Studio and Xcode Debug/Release will be:

cmake -H. -B_builds/xcode -GXcode
cmake --build _builds/xcode --config Debug # build Debug
cmake --build _builds/xcode --config Release # build Release

instead of xcode-debug and xcode-release

Related

Community
  • 1
  • 1