CMake:自定义目标的标志

时间:2012-06-04 16:29:00

标签: cmake

如何以CMakeLists.txt(默认)和all两种方式编写test,其中test目标的标志与{{1}不同目标的标志。问题是当我为测试构建库时,我需要链接一些不应该在发布版本中的东西。

1 个答案:

答案 0 :(得分:4)

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
PROJECT (RootProject)

OPTION(BUILD_TESTING "Build tests." OFF)
IF(BUILD_TESTING)
  # custom compiler option
  ADD_DEFINITIONS(-Zc:wchar_t-)
ENDIF(BUILD_TESTING)


ADD_SUBDIRECTORY(Lib1)
ADD_SUBDIRECTORY(Lib2)
ADD_SUBDIRECTORY(Lib3)
ADD_SUBDIRECTORY(Lib4)
ADD_SUBDIRECTORY(Bin)

IF(BUILD_TESTING)
  # more custom compiler option just for tests
  ADD_DEFINITIONS(-Zc:wchar_t-)

  ADD_SUBDIRECTORY(TestLib1)
  ADD_SUBDIRECTORY(TestLib2)
  ADD_SUBDIRECTORY(TestBin)
  MESSAGE( STATUS "Testing folders have been added." )
ENDIF(BUILD_TESTING)