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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to