AW: [CMake] Overriding default values

James Bigler bigler at cs.utah.edu
Fri Sep 2 12:57:52 EDT 2005


> MACRO(ADD_CXX_FLAGS)
>   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGN}")
> ENDMACRO(ADD_CXX_FLAGS)
> 
> MACRO(ADD_C_FLAGS)
>   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGN}")
> ENDMACRO(ADD_C_FLAGS)
> 
> MACRO(ADD_C_FLAGS_IF condition)
>   IF(${condition})
>     ADD_C_FLAGS(${ARGN})
>   ENDIF(${condition})
> ENDMACRO(ADD_C_FLAGS_IF)
> 
> MACRO(ADD_CXX_FLAGS_IF condition)
>   IF(${condition})
>     ADD_CXX_FLAGS(${ARGN})
>   ENDIF(${condition})
> ENDMACRO(ADD_CXX_FLAGS_IF)
> 
> ADD_CXX_FLAGS("/wd4996")
> 
> ADD_CXX_FLAGS_IF(WIN32 "/wd4996")
> 
>>
>>CMake attempts to provide some values for the following variables:
>>
>>CMAKE_CXX_FLAGS
>>CMAKE_CXX_FLAGS_DEBUG            -g
>>CMAKE_CXX_FLAGS_MINSIZEREL       -O3
>>CMAKE_CXX_FLAGS_RELEASE          -O2
>>CMAKE_CXX_FLAGS_RELWITHDEBINFO   -O2
>>
>>How can I change the default and allow the user to make changes the
>>persists across configuation?
>>

This doesn't work for CMake 1.8 at all (syntax errors).

For 2.0.6, this doesn't add the flag.  I tried it with a fresh configure and an 
old one (with cached values).

MACRO(ADD_CXX_FLAGS)
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGN}")
ENDMACRO(ADD_CXX_FLAGS)

MACRO(ADD_C_FLAGS)
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGN}")
ENDMACRO(ADD_C_FLAGS)

MACRO(ADD_C_FLAGS_IF condition)
   IF(${condition})
     ADD_C_FLAGS(${ARGN})
   ENDIF(${condition})
ENDMACRO(ADD_C_FLAGS_IF)

MACRO(ADD_CXX_FLAGS_IF condition)
   IF(${condition})
     ADD_CXX_FLAGS(${ARGN})
   ENDIF(${condition})
ENDMACRO(ADD_CXX_FLAGS_IF)

###################################################

IF(CMAKE_SYSTEM MATCHES IRIX)
   # For now force sproc on IRIX systems.
   #  MESSAGE("Forcing Irix Threads")
   SET(CMAKE_USE_SPROC_INIT 1)
   SET(CMAKE_USE_PTHREADS_INIT 0)
   SET(CMAKE_THREAD_LIBS_INIT -lfetchop)
   # Check for CC compiler and add -LANG:std to it
   IF(CMAKE_CXX_COMPILER MATCHES "CC")
     ADD_CXX_FLAGS("-LANG:std")
     # Uncomment to force it (which works).
#     SET(CMAKE_CXX_FLAGS "-LANG:std"
#       CACHE STRING "Standard CXX flags" FORCE)
     SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -OPT:IEEE_arithmetic=3"
       CACHE STRING "Optimized Flags" FORCE)
   ENDIF(CMAKE_CXX_COMPILER MATCHES "CC")
ELSE(CMAKE_SYSTEM MATCHES IRIX)
#  MESSAGE("IRIX not found")
ENDIF(CMAKE_SYSTEM MATCHES IRIX)

Thanks,
James


More information about the CMake mailing list