-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
107 lines (96 loc) · 3.32 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
cmake_minimum_required(VERSION 3.12)
project(NBTP)
set(SOVERSION "0.6")
set(PATCHVER "1")
set(VERSION ${SOVERSION}.${PATCHVER})
# Version numbers
set(VERSION_STRING ${VERSION})
add_compile_definitions(NBTP_VERSION=\"${VERSION_STRING}\")
execute_process(COMMAND git rev-parse HEAD
OUTPUT_VARIABLE GIT_SHA1
RESULT_VARIABLE GIT_RET_VAL)
if (${GIT_RET_VAL} EQUAL 0)
string(SUBSTRING ${GIT_SHA1} 0 8 GIT_SHORT_REV)
add_compile_definitions(NBTP_GIT_SHA1=\"${GIT_SHORT_REV}\")
endif (${GIT_RET_VAL} EQUAL 0)
# Environment checks
include(TestBigEndian)
TEST_BIG_ENDIAN(SYSTEM_BIG)
if (SYSTEM_BIG)
add_compile_definitions(SYSTEM_IS_BIG_ENDIAN)
endif ()
# User options
option(NBTP_DEBUG "Build binary with debug symbols" OFF)
option(NBTP_O2 "Build binary with optimization" ON)
option(NBTP_BUILD_TEST "Build unit tests" OFF)
option(NBTP_BUILD_PYTHON_MODULE "Build python module" ON)
if (NBTP_BUILD_PYTHON_MODULE)
option(NBTP_WITH_SYSTEM_PYBIND11 "Use system pybind11" ON)
set(USE_PYTHON_INCLUDE_DIR ON CACHE BOOL "")
endif ()
option(NBTP_BUILD_STATIC_LIB "Build static library as well (Unix only)" OFF)
option(NBTP_COVERAGE "Enable code coverage instrumentation" OFF)
option(NBTP_INSTALL_DEPRECATED_HEADER "Install deprecated headers for compatibility" OFF)
# Windows hacks
if (NBTP_DEBUG OR (CMAKE_BUILD_TYPE STREQUAL "Debug"))
if (NOT MSVC)
add_compile_options("-g")
add_compile_options("-Wall")
add_compile_options("-Wno-unused-variable")
endif ()
endif ()
if (NBTP_COVERAGE)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
add_compile_options("-fprofile-arcs")
add_compile_options("-ftest-coverage")
add_link_options("-lgcov")
add_link_options("--coverage")
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
add_compile_options("-fprofile-instr-generate")
add_compile_options("-fcoverage-mapping")
endif ()
endif()
if (NBTP_O2 AND NOT MSVC)
add_compile_options("-O2")
endif ()
if (MSVC)
add_compile_definitions(ssize_t=uint64_t)
endif()
# Apple Hacks
if (APPLE)
include_directories(SYSTEM ${CMAKE_OSX_SYSROOT}/usr/include)
link_directories(AFTER /opt/local/lib)
endif()
# Compilation options
set(CMAKE_CXX_STANDARD 20)
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib CACHE PATH "Installation directory for libraries")
set(INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Installation directory for headers")
set(INSTALL_PKGCONFIG_DIR ${CMAKE_INSTALL_PREFIX}/share/pkgconfig CACHE PATH "Installation directory for pkgconfig (.pc) files")
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH ${INSTALL_LIB_DIR})
# Dependencies
find_package(fmt REQUIRED)
# Source files
include_directories(include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(pkgconfig)
if (NBTP_BUILD_TEST OR (CMAKE_BUILD_TYPE STREQUAL "Debug"))
if (NOT MSVC)
enable_testing()
# Testing only done on non-msvc because I have no idea how windows works
add_subdirectory(tests)
endif()
endif ()
if (NBTP_BUILD_PYTHON_MODULE)
find_package(Python REQUIRED COMPONENTS Development Interpreter)
if (NBTP_WITH_SYSTEM_PYBIND11)
find_package(pybind11)
else()
add_subdirectory(pybind11)
endif()
set(PYTHON_MODULES_DIR ${Python_SITEARCH})
message("Python module will be placed in ${PYTHON_MODULES_DIR}")
add_subdirectory(pynbtp)
endif ()