-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
114 lines (99 loc) · 4.03 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
# -------------------------------------------------------------------------------------- #
# cmake settings
#
cmake_minimum_required(VERSION 3.8...3.26)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
# Warn about an in-source build, but don't error out
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(STATUS "Warning! Building from the source directory is not recommended")
message(STATUS "If unintented, please remove 'CMakeCache.txt' and 'CMakeFiles'")
message(STATUS "and build from a separate directory")
message(WARNING "In-source build")
endif()
# Check if project is being used directly or via add_subdirectory
set(PTL_MASTER_PROJECT ON)
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(PTL_MASTER_PROJECT OFF)
else()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
# Version
file(READ "${CMAKE_CURRENT_LIST_DIR}/VERSION" VERSION_STRING LIMIT_COUNT 1)
string(REGEX REPLACE "(\n|\r)" "" VERSION_STRING "${VERSION_STRING}")
string(REGEX REPLACE "[A-Za-z].*" "" VERSION_STRING "${VERSION_STRING}")
set(PTL_VERSION "${VERSION_STRING}")
# -------------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------------- #
# project setup
#
project(
PTL
LANGUAGES C CXX
VERSION ${PTL_VERSION})
# Postprocess version info to create variables for export to Version.hh
set(PTL_VERSION_STRING "${PTL_VERSION_MAJOR}.${PTL_VERSION_MINOR}.${PTL_VERSION_PATCH}")
math(EXPR PTL_VERSION_CODE
"10000 * ${PTL_VERSION_MAJOR} + 100 * ${PTL_VERSION_MINOR} + ${PTL_VERSION_PATCH}")
# Project-local CMake settings
set(CMAKE_DIRECTORY_LABELS "PTL")
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Development)
set(CMAKE_INSTALL_MESSAGE LAZY)
set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
include(PTLCMakeUtilities)
# -------------------------------------------------------------------------------------- #
# Build/Install settings and options
include(PTLInstallDirs)
include(PTLBuildSettings)
# -------------------------------------------------------------------------------------- #
# User options
ptl_add_option(PTL_USE_TBB "Enable TBB" ON)
ptl_add_option(PTL_USE_LOCKS "Enable mutex locking in task subqueues for extra safety"
OFF)
ptl_add_option(PTL_INSTALL_HEADERS "Install the headers" ON)
ptl_add_option(PTL_INSTALL_CONFIG "Install the cmake configuration" ON)
if(DEFINED PTL_DEVELOPER_INSTALL)
set(PTL_INSTALL_HEADERS
${PTL_DEVELOPER_INSTALL}
CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
set(PTL_INSTALL_CONFIG
${PTL_DEVELOPER_INSTALL}
CACHE BOOL "Set via PTL_DEVELOPER_INSTALL" FORCE)
endif()
# -------------------------------------------------------------------------------------- #
# Build Dependencies - Threads
if(NOT WIN32)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()
find_package(Threads REQUIRED)
# * TBB
if(PTL_USE_TBB)
find_package(TBB 2017 REQUIRED)
endif()
# -------------------------------------------------------------------------------------- #
# PTL Primary Build
add_subdirectory(source)
# -------------------------------------------------------------------------------------- #
# CMake/PkgConfig Support files
include(PTLPackageConfigHelpers)
# -------------------------------------------------------------------------------------- #
# Examples build/test
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/examples)
ptl_add_option(PTL_BUILD_EXAMPLES "Build examples" OFF)
if(PTL_BUILD_EXAMPLES)
if(CMAKE_CXX_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY)
endif()
set(PTL_DIR ${CMAKE_BINARY_DIR})
add_subdirectory(examples)
endif()
endif()
# -------------------------------------------------------------------------------------- #
# Reporting if master project
if(PTL_MASTER_PROJECT)
ptl_print_features()
endif()