-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
139 lines (106 loc) · 4.06 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
# Detects whether this is a top-level project
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
set(JSE_TOPLEVEL_PROJECT OFF)
else()
set(JSE_TOPLEVEL_PROJECT ON)
endif()
# Check required CMake version
set(REQUIRED_CMAKE_VERSION "3.14.0")
if(JSE_TOPLEVEL_PROJECT)
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
else()
# Don't use cmake_minimum_required here to avoid implicitly overriding parent policies
if(${CMAKE_VERSION} VERSION_LESS ${REQUIRED_CMAKE_VERSION})
message(FATAL_ERROR "CMake required version to build JSE is ${REQUIRED_CMAKE_VERSION}")
endif()
endif()
# Include user-provided default options if available. We do that before the main
# `project()` so that we can define the C/C++ compilers from the option file.
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/JSEOptions.cmake)
message(STATUS "Using local options file: ${CMAKE_CURRENT_SOURCE_DIR}/JSEOptions.cmake")
include(${CMAKE_CURRENT_SOURCE_DIR}/JSEOptions.cmake)
endif()
################################################################################
project(JSE
DESCRIPTION "JSON Specs Engine"
LANGUAGES CXX)
# JSE options
option(JSE_WITH_SANITIZERS "Enable sanitizers in compilation targets" OFF)
# Misc.
option(JSE_WITH_TESTS "Build unit-tests" ${JSE_TOPLEVEL_PROJECT})
option(JSE_WITH_APP "Compiles applications" ${JSE_TOPLEVEL_PROJECT})
include(CMakeDependentOption)
# Set default minimum C++ standard
if(JSE_TOPLEVEL_PROJECT)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif()
### Configuration
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/jse/")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/")
# Color output
include(jse_use_colors)
# IPC Toolkit utils
include(jse_prepend_current_path)
include(jse_set_source_group)
# Sort projects inside the solution
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Generate position independent code by default
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
################################################################################
# JSE Library
################################################################################
# Add an empty library and fill in the list of sources in `src/CMakeLists.txt`.
add_library(jse)
add_library(jse::jse ALIAS jse)
add_subdirectory(src)
# Public include directory for JSE
target_include_directories(jse PUBLIC ${PROJECT_SOURCE_DIR}/src)
################################################################################
# Dependencies
################################################################################
# Extra warnings
include(jse_warnings)
target_link_libraries(jse PRIVATE jse::warnings)
# Sanitizers
if(JSE_WITH_SANITIZERS)
include(sanitizers)
add_sanitizers(jse)
endif()
# Json (MIT)
include(json)
target_link_libraries(jse PUBLIC nlohmann_json::nlohmann_json)
################################################################################
# Compiler options
################################################################################
# Use C++17
target_compile_features(jse PUBLIC cxx_std_17)
################################################################################
# Tests
################################################################################
# Compile extras only if this is a top-level project
if(JSE_WITH_TESTS)
# Unit tests
include(CTest)
enable_testing()
# Include Catch2 and provide function `catch_discover_tests` to register tests.
include(catch2)
FetchContent_GetProperties(catch2)
include("${catch2_SOURCE_DIR}/contrib/Catch.cmake")
add_subdirectory(tests)
endif()
################################################################################
# Applications
################################################################################
if(JSE_WITH_APP)
add_executable(jse_app src/main.cpp)
target_compile_options(jse_app PRIVATE "-rdynamic")
target_link_libraries(jse_app PUBLIC
jse::jse
)
endif()