-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
103 lines (85 loc) · 4.19 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
cmake_minimum_required(VERSION 2.6)
project(sea)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_FLAGS -pthread)
set(PROJECT_SOURCE_DIR .)
set(COVERAGE OFF CACHE BOOL "Coverage")
# Project Structure
set(LIBRARY_OUTPUT_PATH lib) # generated library files
set(EXECUTABLE_OUTPUT_PATH bin) # generated binary files
set(CMAKE_INCLUDE_PATH include/)
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
set(WARNING_FLAGS "-Wall -Wextra -Wpedantic -Wdeprecated")
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(WARNING_FLAGS "${WARNING_FLAGS} -Werror -Wdocumentation")
endif()
set(BUILD_FLAGS "-std=c++17 -O3 -fno-builtin -fno-rtti -ffast-math ${WARNING_FLAGS}")
set(TEST_FLAGS "-std=c++17 -g -O0 -fno-builtin -fno-rtti -ffast-math ${WARNING_FLAGS}")
# --------------------------------------------------- #
# Dependencies
# --------------------------------------------------- #
include(ExternalProject)
find_program(MAKE NAMES cmake make)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# --------------------------------------------------- #
# gtest library
# --------------------------------------------------- #
ExternalProject_Add(GTEST_PROJECT
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG dea0216d0c6bc5e63cf5f6c8651cd268668032ec
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/third-party/gtest
CMAKE_ARGS -DINSTALL_GTEST=OFF -DCMAKE_CXX_FLAGS=-std=c++17 -fpermissive -stdlib=libc++
INSTALL_COMMAND ""
BUILD_COMMAND "${MAKE}" --build .)
ExternalProject_Get_Property(GTEST_PROJECT source_dir)
ExternalProject_Get_Property(GTEST_PROJECT binary_dir)
set(GOOGLETEST_ROOT ${source_dir})
set(GOOGLETEST_BIN ${binary_dir})
MESSAGE(STATUS "GTest source_dir: ${GOOGLETEST_ROOT}")
MESSAGE(STATUS "GTest build_dir: ${GOOGLETEST_BIN}")
include_directories(SYSTEM ${GOOGLETEST_ROOT}/googletest/)
include_directories(SYSTEM ${GOOGLETEST_ROOT}/googletest/include)
add_library(gtest STATIC IMPORTED benchmark/main.cpp)
add_dependencies(gtest GTEST_PROJECT)
set_property(TARGET gtest PROPERTY IMPORTED_LOCATION "${GOOGLETEST_BIN}/googlemock/gtest/libgtest.a")
# --------------------------------------------------- #
# build library
# --------------------------------------------------- #
include_directories(${CMAKE_INCLUDE_PATH})
file(GLOB LIB_SOURCES "src/*.cpp" "src/*/*.cpp")
add_library(sealib SHARED ${LIB_SOURCES})
# --------------------------------------------------- #
# build tests
# --------------------------------------------------- #
file(GLOB TESTS "test/*.cpp") # all test files
add_executable(tests ${LIB_SOURCES} ${TESTS})
add_dependencies(tests gtest)
set(TEST_LINK_FLAGS "")
if (COVERAGE)
MESSAGE(STATUS "Link Coverage")
set(TEST_FLAGS "${TEST_FLAGS} --coverage")
set(TEST_LINK_FLAGS "--coverage")
elseif (PROFILING AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"))
MESSAGE(STATUS "Profiling: ENABLED")
set(TEST_FLAGS "${TEST_FLAGS} -pg -no-pie")
set(TEST_LINK_FLAGS "-pg -no-pie")
endif ()
# --------------------------------------------------- #
# build main
# --------------------------------------------------- #
file(GLOB MAIN "src-view/*.cpp") # all test files
add_executable(main ${LIB_SOURCES} ${MAIN})
find_package(Threads)
set_target_properties(main PROPERTIES LINK_FLAGS "${CMAKE_THREAD_LIBS_INIT}")
set_target_properties(tests PROPERTIES LINK_FLAGS "${TEST_LINK_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(tests gtest)
set_target_properties(tests PROPERTIES COMPILE_FLAGS ${TEST_FLAGS})
# --------------------------------------------------- #
# build benchmark
# --------------------------------------------------- #
file(GLOB BENCHMARK "benchmark/*.[ch]pp") # all test files
add_executable(benchmark ${LIB_SOURCES} ${BENCHMARK})
find_package(Threads)
set_target_properties(benchmark PROPERTIES LINK_FLAGS "${CMAKE_THREAD_LIBS_INIT}")
set_target_properties(sealib main benchmark PROPERTIES COMPILE_FLAGS ${BUILD_FLAGS})