[CMake] compile options

Ingrid Kemgoum ingrid.kemgoum at gmail.com
Thu Jun 19 05:44:50 EDT 2008


hi,
here is a small example (hello World example).
i have 2 subdirs Hello (shared lib) and Demo (calling Hello functions)

in Demo we have

*cmake_minimum_required(VERSION 2.6)*
*# Make sure the compiler can find include files from our Hello library. les
fichiers ou se trouvent le code, donc ou se trouve les cmakelists
include_directories (${ORIGIN}/Hello)*
*# Make sure the linker can find the Hello library once it is built. le
dossier ou va etre placé lensemble des resultats de la fabriction du projet
link_directories (${HELLO_BINARY_DIR}/Hello)*
*# Add executable called "helloDemo" that is built from the source files
# "demo.cxx" and "demo_b.cxx".  The extensions are automatically found.
add_executable (helloDemo ${ORIGIN}/Demo/demo.cxx ${ORIGIN}/Demo/demo_b.cxx
)*

*# Link the executable to the Hello library.
target_link_libraries (helloDemo Hello)*
**

*if(MSVC_VERSION)
 #flags dans le cas release
 IF(CMAKE_BUILD_TYPE MATCHES Release|Win32)
       set_target_properties(helloDemo PROPERTIES
   LINK_FLAGS "/SUBSYSTEM:CONSOLE /MACHINE:X86 /MANIFEST /NOLOGO /DEBUG
/mktyplib203"
   COMPILE_FLAGS "/GF /Od /W3 /Z7 /Od /MTd /NOLOGO"
  )
 #Endif(CMAKE_BUILD_TYPE MATCHES Release|Win32)

 #flags dans le cas debug
 elseIF(CMAKE_BUILD_TYPE MATCHES Debug|Win32)
  set_target_properties(helloDemo PROPERTIES
   LINK_FLAGS "/SUBSYSTEM:CONSOLE /INCREMENTAL:NO /MACHINE:X86 /MANIFEST
/NOLOGO /DEBUG /mktyplib203"
   COMPILE_FLAGS "/GF /Od /W3 /Z7 /Od /MTd"
  )
 #ENDIF(CMAKE_BUILD_TYPE MATCHES Debug|Win32)
 Endif(CMAKE_BUILD_TYPE MATCHES Release|Win32) #attention rajouté*
*endif(MSVC_VERSION)*

and there is no problem, all the flags are set.

In Hello, i want different flags in Debug and Release and i have

*add_library (Hello SHARED ${ORIGIN}/Hello/hello.cxx
${ORIGIN}/Hello/hello.h)*
*message(status :" on est passé de add lib")
#set(DEBUG_OUTPUT_NAME "ingridd_so") # ne marche pas à l'exterieur
set(VARIAB "DEBUG")*
*#set(CMAKE_CONFIGURATION_TYPES [Debug, Release]) #a tester pr voir si
restreint les types a ces deux la*
*message (status : "la valeur de la connerie la que je ne connais pas est :
${CMAKE_INTDIR}")*
*if(MSVC_VERSION)
 message(status " : on traaite le cas de visual studio!!!!!!!!!!!!!!!!! pur
un debut")

  IF (${CMAKE_CFG_INTDIR} MATCHES "Debug")
  #ATTENTION : DO NOT USE BOTH SET_TARGET_PROP AND ADD_DEFINITIONS
      set_target_properties(Hello PROPERTIES

    #COMPILE OPTIONS IN DEBUG AND RELEASE
    #CMAKE_CXX_FLAGS_RELEASE "/Gz /GF /Gy /Od /W3 /ZI /Od /MTd"
    #CMAKE_CXX_FLAGS_DEBUG "/Od /MDd /W3 /nologo /Z7 /Gz /TC"

    COMPILE_FLAGS "/Od /MDd /W3 /nologo /Z7 /Gz /TC"

    #LINK OPTIONS IN DEBUG AND RELEASE
    LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE /INCREMENTAL:NO /MACHINE:X86
/MANIFEST /NOLOGO /DEBUG"
*
*    LINK_FLAGS_RELEASE "/SUBSYSTEM:CONSOLE /INCREMENTAL:NO /MACHINE:X86
/MANIFEST /NOLOGO /DEBUG "
    #COMPILE_FLAGS_RELEASE "/GF /Od /W3 /Z7 /Od /MTd"  #DO NOT WORK

   )
  else (${CMAKE_CFG_INTDIR} MATCHES "Debug")
   set_target_properties(Hello PROPERTIES

    #COMPILE OPTIONS IN DEBUG AND RELEASE
    #CMAKE_CXX_FLAGS_RELEASE "/Gz /GF /Gy /Od /W3 /ZI /Od /MTd"
    #CMAKE_CXX_FLAGS_DEBUG "/Od /MDd /W3 /nologo /Z7 /Gz /TC"

    COMPILE_FLAGS "/O2 /MDd /W3 /nologo /Z7 /Gz /TC"

    LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE /INCREMENTAL:NO /MACHINE:X86
/MANIFEST /NOLOGO /DEBUG"
        LINK_FLAGS_RELEASE "/SUBSYSTEM:CONSOLE /INCREMENTAL:NO /MACHINE:X86
/MANIFEST /NOLOGO /DEBUG "
    #COMPILE_FLAGS_RELEASE "/GF /Od /W3 /Z7 /Od /MTd"  #DO NOT WORK
    ENABLE_EXPORTS "true"
   )
  endif(${CMAKE_CFG_INTDIR} MATCHES "Debug")
endif(MSVC_VERSION)
*


when using compile_flags, everything goes well (i have al the flags i've
asked for)
but with CMAKE_CXX_FLAGS_DEBUG i have nothing (just default MSVC flags).

Thanks.




2008/6/18 Bill Hoffman <bill.hoffman at kitware.com>:

>  Eric Noulard wrote:
>
>> 2008/6/18 Ingrid Kemgoum <ingrid.kemgoum at gmail.com>:
>>
>>> yes i do have read that.
>>> it's why i've tried CMAKE_CXX_FLAGS_<config>. (<config> for DEBUG and
>>> RELEASE).
>>> but that have no effect on MSVC flags.
>>> (on Unix after fixing the build type first, the CMAKE_CXX_FLAGS_<config>
>>> works but not on windows!)
>>>
>>
>> Ok then it may be a MSVC specific pb.
>> I'm afraid I won't be able to help for that config :=(
>>
>> These options certainly do affect MSVC.  I suspect that your project is
> doing something funny.  Please post a "small" example that shows the flags
> are not being used.
>
> -Bill
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080619/565eaa7d/attachment.htm>


More information about the CMake mailing list