[CMake] Alternative default CMAKE_C_STANDARD_LIBRARIES_INIT
Campbell Barton
ideasman42 at gmail.com
Sun Apr 10 09:31:43 EDT 2011
Yesterday I found there was a bug caused by the default linking flags
(-ladvapi32 with mingw incidentally was crashing with "%.*f" printf()
formatting).
So I tried to override CMAKE_C_STANDARD_LIBRARIES &
CMAKE_C_STANDARD_LIBRARIES_INIT but wasn't able to find any nice way
of doing it.
the problem is that project(...) sets both
CMAKE_C_STANDARD_LIBRARIES_INIT and CMAKE_C_STANDARD_LIBRARIES so
there is nowhere you can add in your own overrides/replacements.
This issue is that I want to make it as if
CMAKE_C_STANDARD_LIBRARIES_INIT didnt include -ladvapi32, but
otherwise works the same as it does now.
its easy to clobber CMAKE_C_STANDARD_LIBRARIES on every run but then
the cached value isnt any use (since the dev building may want to
set).
So the solution I found is to check if the value is defined, if not,
override it after the project(...) is defined, saving the cache.
this works but I was wondering if there was a better way.
# ------ snip
if(DEFINED CMAKE_C_STANDARD_LIBRARIES)
set(_reset_standard_libraries OFF)
else()
set(_reset_standard_libraries ON)
endif()
project(MyProject)
if (_reset_standard_libraries)
set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
mark_as_advanced(CMAKE_C_STANDARD_LIBRARIES)
mark_as_advanced(CMAKE_CXX_STANDARD_LIBRARIES)
endif()
unset(_reset_standard_libraries)
# ------
--
- Campbell
More information about the CMake
mailing list