-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
202 lines (173 loc) · 5.94 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
CMAKE_MINIMUM_REQUIRED( VERSION 3.10 )
PROJECT( cppcore )
SET ( CPPCORE_VERSION_MAJOR 0 )
SET ( CPPCORE_VERSION_MINOR 1 )
SET ( CPPCORE_VERSION_PATCH 0 )
SET ( CPPCORE_VERSION ${CPPCORE_VERSION_MAJOR}.${CPPCORE_VERSION_MINOR}.${CPPCORE_VERSION_PATCH} )
SET ( PROJECT_VERSION "${CPPCORE_VERSION}" )
find_package(GTest)
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
find_package(Threads)
endif()
set(CMAKE_CXX_STANDARD 14)
option( CPPCORE_BUILD_UNITTESTS
"Build unit tests."
ON
)
option( CPPCORE_ASAN
"Enable AddressSanitizer."
OFF
)
option( CPPCORE_UBSAN
"Enable Undefined Behavior sanitizer."
OFF
)
add_definitions( -DCPPCORE_BUILD )
add_definitions( -D_VARIADIC_MAX=10 )
add_definitions( -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1)
INCLUDE_DIRECTORIES( BEFORE
include/
)
link_directories(
${CMAKE_HOME_DIRECTORY}/
)
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin )
if( WIN32 AND NOT CYGWIN )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" ) # Force to always compile with W4
if( CMAKE_CXX_FLAGS MATCHES "/W[0-4]" )
string( REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
else()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" )
endif()
elseif( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -g -pedantic -std=c++0x")
elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -g -pedantic -std=c++11")
endif()
IF (ASSIMP_ASAN)
MESSAGE(STATUS "AddressSanitizer enabled")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
ENDIF()
IF (ASSIMP_UBSAN)
MESSAGE(STATUS "Undefined Behavior sanitizer enabled")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
ENDIF()
SET ( cppcore_src
code/cppcore.cpp
include/cppcore/CPPCoreCommon.h
)
SET ( cppcore_common_src
include/cppcore/Common/Hash.h
include/cppcore/Common/TStringBase.h
include/cppcore/Common/Variant.h
include/cppcore/Common/Sort.h
include/cppcore/Common/TBitField.h
include/cppcore/Common/TOptional.h
)
SET( cppcore_random_src
include/cppcore/Random/RandomGenerator.h
code/Random/RandomGenerator.cpp
)
SET ( cppcore_container_src
include/cppcore/Container/THashMap.h
include/cppcore/Container/TArray.h
include/cppcore/Container/TStaticArray.h
include/cppcore/Container/TList.h
include/cppcore/Container/TQueue.h
include/cppcore/Container/TStaticArray.h
)
SET ( cppcore_memory_src
include/cppcore/Memory/MemUtils.h
include/cppcore/Memory/TDefaultAllocator.h
include/cppcore/Memory/TStackAllocator.h
include/cppcore/Memory/TPoolAllocator.h
code/Memory/MemUtils.cpp
)
SET( cppcore_io_src
include/cppcore/IO/FileSystem.h
)
SOURCE_GROUP( code FILES ${cppcore_src} )
SOURCE_GROUP( code\\common FILES ${cppcore_common_src} )
SOURCE_GROUP( code\\container FILES ${cppcore_container_src} )
SOURCE_GROUP( code\\io FILES ${cppcore_io_src} )
SOURCE_GROUP( code\\memory FILES ${cppcore_memory_src} )
SOURCE_GROUP( code\\random FILES ${cppcore_random_src} )
ADD_LIBRARY( cppcore SHARED
${cppcore_container_src}
${cppcore_common_src}
${cppcore_memory_src}
${cppcore_random_src}
${cppcore_io_src}
${cppcore_src}
README.md
)
IF( CPPCORE_BUILD_UNITTESTS )
SET( cppcore_test_src
test/CPPCoreCommonTest.cpp
)
SET( cppcore_common_test_src
test/common/HashTest.cpp
test/common/VariantTest.cpp
test/common/SortTest.cpp
test/common/TBitFieldTest.cpp
test/common/TOptionalTest.cpp
)
SET( cppcore_container_test_src
test/container/TArrayTest.cpp
test/container/TAlgorithmTest.cpp
test/container/THashMapTest.cpp
test/container/TListTest.cpp
test/container/TQueueTest.cpp
test/container/TStaticArrayTest.cpp
)
SET( cppcore_io_test_src
test/io/FileSystemTest.cpp
)
SET( cppcore_memory_test_src
test/memory/TStackAllocatorTest.cpp
test/memory/TPoolAllocatorTest.cpp
test/memory/TScratchAllocatorTest.cpp
)
SET( cppcore_random_test_src
test/random/RandomGeneratorTest.cpp
)
SOURCE_GROUP(code FILES ${cppcore_test_src} )
SOURCE_GROUP(code\\common FILES ${cppcore_common_test_src} )
SOURCE_GROUP(code\\io FILES ${cppcore_io_test_src} )
SOURCE_GROUP(code\\container FILES ${cppcore_container_test_src} )
SOURCE_GROUP(code\\memory FILES ${cppcore_memory_test_src} )
SOURCE_GROUP(code\\random FILES ${cppcore_random_test_src} )
# Prevent overriding the parent project's compiler/linker
# settings on Windows
SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
if (GTest_FOUND)
SET(test_libs GTest::gtest_main)
else()
SET(test_libs gtest_main)
SET ( GTEST_PATH ../contrib/googletest-1.15.2 )
INCLUDE_DIRECTORIES(
contrib/googletest-1.15.2/googletest/include
contrib/googletest-1.15.2/googletest
)
ADD_SUBDIRECTORY( contrib/googletest-1.15.2/ )
endif()
ADD_EXECUTABLE( cppcore_unittest
${cppcore_test_src}
${cppcore_common_test_src}
${cppcore_io_test_src}
${cppcore_memory_test_src}
${cppcore_random_test_src}
${cppcore_container_test_src}
)
IF( WIN32 )
SET( platform_libs )
ELSE( WIN32 )
SET( platform_libs pthread )
ENDIF( WIN32 )
target_link_libraries( cppcore_unittest cppcore ${CMAKE_THREAD_LIBS_INIT} ${platform_libs} ${test_libs})
ENDIF()