如何以CMakeLists.txt
(默认)和all
两种方式编写test
,其中test
目标的标志与{{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)