-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
72 lines (55 loc) · 1.86 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(immutable)
add_definitions(
-std=c++11 -g
)
include_directories(${CMAKE_SOURCE_DIR}/src)
## Google test framework setup
# Enable external projects
include(ExternalProject)
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/vendor)
file(WRITE ${CMAKE_BINARY_DIR}/gtest.patch "")
# Add gtest
ExternalProject_Add(
googletest
SVN_REPOSITORY http://googletest.googlecode.com/svn/trunk/
SVN_REVISION -r 660
TIMEOUT 10
PATCH_COMMAND svn patch ${CMAKE_BINARY_DIR}/gtest.patch ${CMAKE_BINARY_DIR}/vendor/src/googletest
# Force separate output paths for debug and release builds to allow easy
# identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
-Dgtest_force_shared_crt=ON
# Disable install step
INSTALL_COMMAND ""
# Wrap download, configure and build steps in a script to log output
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON)
# Specify include dir
ExternalProject_Get_Property(googletest source_dir)
include_directories(${source_dir}/include)
include_directories(${source_dir}/gtest/include)
## Testing setup
enable_testing()
# Add test file
file(GLOB test_cpp "test/*_test.cpp")
add_executable(unitTests
${PROJECT_SOURCE_DIR}/test/main.cpp
${test_cpp}
)
add_dependencies(unitTests googletest)
# Linking for tests
ExternalProject_Get_Property(googletest binary_dir)
set(Suffix ".a")
target_link_libraries(
unitTests
${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${Suffix}
pthread
)
# test
add_test(unitTests unitTests)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
DEPENDS unitTests)