generated from TheLartians/ModernCppStarter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
118 lines (90 loc) · 3.72 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
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
# ---- Project ----
# Note: update this to your new project's name and version
project(Sortnet
VERSION 1.0
LANGUAGES CXX
)
# ---- Include guards ----
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()
# --- Import tools ----
include(cmake/tools.cmake)
# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info
include(cmake/CPM.cmake)
# PackageProject.cmake will be used to make our target installable
CPMAddPackage(
NAME PackageProject.cmake
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
VERSION 1.0
)
#CPMAddPackage(
# NAME libpopcnt
# GITHUB_REPOSITORY andersfylling/libpopcnt
# VERSION 2.3.2
#)
CPMAddPackage(
NAME nlohmann_json
VERSION 3.7.3
# the git repo is incredibly large, so we download the archived include directory
URL https://github.com/nlohmann/json/releases/download/v3.7.3/include.zip
URL_HASH SHA256=87b5884741427220d3a33df1363ae0e8b898099fbc59f1c451113f6732891014
)
if (nlohmann_json_ADDED)
add_library(nlohmann_json INTERFACE IMPORTED)
target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR}/include)
endif()
#CPMAddPackage(
# NAME boost
# VERSION 1.70.0
# URL https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz
# URL_HASH SHA256=882b48708d211a5f48e60b0124cf5863c1534cd544ecd0664bb534a4b5d506e9
#)
#
#if (boost_ADDED)
# add_library(boost INTERFACE IMPORTED)
# target_include_directories(boost INTERFACE "${boost_SOURCE_DIR}")
#endif()
#CPMAddPackage(
# NAME Boost
# GITHUB_REPOSITORY Orphis/boost-cmake
# GIT_TAG origin/master
# FIND_PACKAGE_ARGUMENTS "COMPONENTS system"
#)
find_package(Threads REQUIRED)
# ---- Add source files ----
# Note: globbing sources is considered bad practice as CMake's generators may not detect new files automatically.
# Keep that in mind when changing files, or explicitly mention them here.
FILE(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/**/**/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.h"
"app/src/vendors/github.com/dabbertorres/ThreadPool/ThreadPool.h"
)
FILE(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/**/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
"app/src/vendors/github.com/dabbertorres/ThreadPool/ThreadPool.cpp"
)
# ---- Create library ----
# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface target:
# add_library(Greeter INTERFACE)
# set_target_properties(Greeter PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_17)
# set(CMAKE_REQUIRED_FLAGS -fconcepts)
add_library(Sortnet STATIC ${headers} ${sources})
set_target_properties(Sortnet PROPERTIES CXX_STANDARD 20)
# beeing a cross-platform target, we enforce enforce standards conformance on MSVC
target_compile_options(Sortnet PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")
# Link dependencies (if required)
target_link_libraries(Sortnet PUBLIC nlohmann_json Threads::Threads)
target_include_directories(Sortnet
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)
# ---- Create an installable target ----
# this allows users to install and find the library via `find_package()`.
packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
)