Reputation: 5586
How can I write CMakeLists.txt
in a way it has two targets all
(default) and test
, where test
target has flags that differ from all
target's flags. The problem is that when I build libraries for tests I need to link some stuff that shouldn't be in release build.
Upvotes: 2
Views: 2601
Reputation: 7744
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)
Upvotes: 4