[CMake] Overriding CFLAGS/CXXFLAGS
Paolo Zani
paolo.zani at gmail.com
Mon Mar 23 13:47:38 EDT 2009
I'm trying to set the CFLAGS/CXXFLAGS for a project to values that depend on
the compiler (and relative version) in use and the system CPU, detected
through the kwsys facilities, like this:
cmake_minimum_required (VERSION 2.6)
project(Dummy)
SET(KWSYS_NAMESPACE sys_info)
SET(KWSYS_USE_FundamentalType 1)
SET(KWSYS_USE_Process 1)
SET(KWSYS_USE_SystemInformation 1)
SUBDIRS(kwsys)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/kwsys)
TRY_RUN(COMPILE_RESULT RUN_RESULT
${PROJECT_BINARY_DIR}/CMakeTmp
${PROJECT_SOURCE_DIR}/flags_main.cpp
CMAKE_FLAGS -DINCLUDE_DIRECTORIES:STRING=${CMAKE_BINARY_DIR}/kwsys
-DLINK_DIRECTORIES:STRING=${PROJECT_BINARY_DIR}/kwsys
-DLINK_LIBRARIES:STRING=${KWSYS_NAMESPACE}
RUN_OUTPUT_VARIABLE RUN_OUTPUT)
[...] # <---- OVERRIDE CFLAGS HERE
SUBDIRS(project_src)
with flags_main.cpp producing the appropriate flags line.
The problem with this approach is that TRY_RUN only gets executed when make
is invoked, and so far I haven't found a decent way of setting the flags so
that the contents of project_src gets built with the correct flags straight
away: using
SET(CMAKE_CXX_FLAGS_RELEASE ${RUN_OUTPUT} CACHE STRING blah FORCE)
won't work since it requires a (re)configuration to propagate the change,
while splitting the project in two, with a binary that generates a default
cache file to import with CMAKE_USER_MAKE_RULES_OVERRIDE doesn't seem an
option either (too bloated as an approach, and it requires different scripts
on different platforms).
Any suggestions?
--
Paolo Zani, PhD
VisLab.it - Artificial Vision and Intelligent Systems Lab.
Dipartimento di Ingegneria dell'Informazione
Università di Parma
via G.P. Usberti 181/A
I-43100 Parma - ITALY
web http://www.vislab.it/zani/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090323/80aa4d69/attachment.htm>
More information about the CMake
mailing list