1

I've got something like this in the CMakeLists file:

set(CMAKE_CXX_FLAGS "-g -Wextra -DFLAG")

Later in the same CMakeLists.txt file, I need to check if FLAG has been defined. Is it possible to do something like this?

IF(FLAG)
    target_link_libraries(${PRODUCT} ${LIBS1}) 
ELSE()
    target_link_libraries(${PRODUCT} ${LIBS2}) 
ENDIF()

I am also gonna check if FLAG has been defined in my c++ code. If defined, I will use codes from LIBS1, else I will make use of codes defined in LIBS2 library set.

#ifdef FLAG
  // some code that uses LIBS1 libraries 
#else
  // some code that uses LIBS2 libraries  
#endif
4

1 回答 1

1

我不知道直接的方法,但您可以使用字符串匹配来获取标志:

STRING(REGEX MATCH "FLAG" result ${CMAKE_CXX_FLAGS})
IF(${result} MATCHES "FLAG"))
    #Add your code
ENDIF()
于 2013-06-03T10:09:08.563 回答