We use a SuperBuild and need to pass extra compiler flags on Windows with Visual Studio to the (CMake-based) external project. We have no control over the project.
My strategy was to do something like
ExternalProject_Add(... CMAKE_ARGS -DCMAKE_CXX_FLAGS:STRING="-DBOOST_ALL_DYN_LINK" )
I have 2 problems:
- this overrides
CMAKE_CXX_FLAGSset by CMake itself. This is for Visual Studio Generator a disaster, as it sets
CMAKE_CXX_FLAGS=/DWIN32 /D_WINDOWS /W3 /GR /EHsc. I suppose I could resolve this by using the existing
CMAKE_CXX_FLAGSas well, but…
- I cannot find a way to set more than 1 flag this way, I’ve tried
CMAKE_CXX_FLAGS="-DFlag1 -DFlag2"(which actually sets a variable
CMAKE_CXX_FLAGS=-DFlag1 -DFlag2(which sets the first variable, but let CMake complain that
-DFlag2is not a CMake flag)
CMAKE_CXX_FLAGS=-DFlag1;-DFlag2(which does the same as the previous variable)
I suppose we could use
PATCH_COMMAND to patch the original project but according to the CMake doc that sounds difficult as we use
thanks for any help.
PS: Final piece of information is that we need to set
BOOST_ALL_DYN_LINK on Windows to get the project to link Boost files, which is difficult as we don’t know what the user has installed for Boost libraries. (sadly
FindBoost doesn’t take care of this, but that is off-topic).