<div dir="ltr"><div style="font-size:12.8000001907349px">I'm having some problem with custom configurations in combination with multiple cmake projects.<br></div><div style="font-size:12.8000001907349px">Basically what I have is some helper function/macro which sets the available configurations, sets the CMAKE_CXX_FLAGS_<configname> etc.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">I do this with:</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px"><div><span style="white-space:pre-wrap">              </span>set(CMAKE_CONFIGURATION_TYPES Debug Release)</div><div><span style="white-space:pre-wrap">             </span>set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "The available configuration types." FORCE)</div></div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Then per target, i set the compiler and linker flags per configuration.</div><div style="font-size:12.8000001907349px">Such as:</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px"><div><span style="white-space:pre-wrap">               </span>set(CMAKE_CXX_FLAGS_DEBUG<span style="white-space:pre-wrap">                               </span>"/MP /GS /analyze- /Zc:wchar_t /Zi /Gm- /Od /Ob1 /fp:fast /errorReport:prompt /Zc:forScope /GR- /Gd /Oy- /Oi /EHa /nologo /D \"DEBUG\" /D \"_DEBUG\" ${CUSTOM_CXX_WARNINGFLAGS} ${CUSTOM_CXX_ARCH_FLAGS} ${CUSTOM_CXX_RUNTIMEFLAG} ${CUSTOM_CXX_OPENMP}" CACHE STRING "Flags used by the C++ compiler during this build." FORCE )</div><div><span style="white-space:pre-wrap">                </span>set(CMAKE_C_FLAGS_DEBUG <span style="white-space:pre-wrap">                               </span>"" CACHE STRING "Flags used by the C compiler during this build." FORCE )</div><div><span style="white-space:pre-wrap">            </span>set(CMAKE_EXE_LINKER_FLAGS_DEBUG <span style="white-space:pre-wrap">              </span>"${CUSTOM_LINKER_FLAGS} /DEBUG" CACHE STRING "Flags used for linking binaries during this build." FORCE )</div><div><span style="white-space:pre-wrap">            </span>set(CMAKE_SHARED_LINKER_FLAGS_DEBUG <span style="white-space:pre-wrap">   </span>"${CUSTOM_LINKER_FLAGS} /DEBUG" CACHE STRING "Flags used by the shared libraries linker during this build." FORCE )</div><div><span style="white-space:pre-wrap">          </span>set(CMAKE_STATIC_LINKER_FLAGS_DEBUG <span style="white-space:pre-wrap">   </span>"${CMAKE_STATIC_LINKER_FLAGS_DEBUG} ${CUSTOM_LINKER_FLAGS} /DEBUG" CACHE STRING "Flags used by the static libraries linker during this build." FORCE )</div><div><span style="white-space:pre-wrap">               </span>MARK_AS_ADVANCED(CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG CMAKE_EXE_LINKER_FLAGS_DEBUG CMAKE_SHARED_LINKER_FLAGS_DEBUG CMAKE_STATIC_LINKER_FLAGS_DEBUG)</div><div><span style="white-space:pre-wrap">         </span>#-------------------------------------------------------------------------------------------------------------</div><div><span style="white-space:pre-wrap">           </span>set(CMAKE_CXX_FLAGS_RELEASE<span style="white-space:pre-wrap">                             </span>"/MP /GS /analyze- /Zc:wchar_t /Zi /Gm- /O2 /Ob2 /fp:fast /errorReport:prompt /Zc:forScope /GR- /Gd /Oy- /Oi /EHa /nologo /Ot /D \"NDEBUG\" ${CUSTOM_CXX_WARNINGFLAGS} ${CUSTOM_CXX_ARCH_FLAGS} ${CUSTOM_CXX_RUNTIMEFLAG} ${CUSTOM_CXX_OPENMP}" CACHE STRING "Flags used by the C++ compiler during this build." FORCE )</div><div><span style="white-space:pre-wrap">           </span>set(CMAKE_C_FLAGS_RELEASE <span style="white-space:pre-wrap">                             </span>"" CACHE STRING "Flags used by the C compiler during this build." FORCE )</div><div><span style="white-space:pre-wrap">            </span>set(CMAKE_EXE_LINKER_FLAGS_RELEASE <span style="white-space:pre-wrap">            </span>"${CUSTOM_LINKER_FLAGS}" CACHE STRING "Flags used for linking binaries during this build." FORCE )</div><div><span style="white-space:pre-wrap">           </span>set(CMAKE_SHARED_LINKER_FLAGS_RELEASE <span style="white-space:pre-wrap"> </span>"${CUSTOM_LINKER_FLAGS}" CACHE STRING "Flags used by the shared libraries linker during this build." FORCE )</div><div><span style="white-space:pre-wrap">         </span>set(CMAKE_STATIC_LINKER_FLAGS_RELEASE <span style="white-space:pre-wrap"> </span>"${CUSTOM_LINKER_FLAGS}" CACHE STRING "Flags used by the static libraries linker during this build." FORCE )</div><div><span style="white-space:pre-wrap">         </span>MARK_AS_ADVANCED(CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_EXE_LINKER_FLAGS_RELEASE CMAKE_SHARED_LINKER_FLAGS_RELEASE CMAKE_STATIC_LINKER_FLAGS_RELEASE)</div></div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Now I'm making some project that uses add_subdirectory(...) to add other cmake projects.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">But doing that seems to overwrite the settings all the time with flags set by other projects.</div><div style="font-size:12.8000001907349px">So if i adjust the warning level in one project then once generated (for visual studio), it has the warning level of another cmake project, as that has overwritten the compiler flags.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Am I doing something wrong here?</div><div style="font-size:12.8000001907349px">I tried to not cache and force the values, but that didnt work at all. Then CMake uses its default values everywhere.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Basically I need unique per project, per configuration compiler and linker flags, but somehow I can't manage to get that working as when i add_subdirectory other projects they overwrite each others settings.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">If someone has some hints, that would be cool :)</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Also I noticed there is a COMPILE_FLAGS target property for set_target_properties</div><div style="font-size:12.8000001907349px">That can be used to setup additional flags per target. But it has no support for different configurations it seems, while the LINKER_FLAGS option (i think its named like that) has, which seems odd.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Cheers,</div><div style="font-size:12.8000001907349px">- John</div></div>