-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
90 lines (75 loc) · 2.41 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
cmake_minimum_required(VERSION 3.22)
project(Sodium VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Options
option(SODIUM_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(SODIUM_BUILD_DOC "Build documentation" OFF)
option(SODIUM_BUILD_EXAMPLES "Build examples" ON)
option(SODIUM_BUILD_TESTS "Build tests" OFF)
option(SODIUM_ENABLE_PCH "Enable precompiled headers" OFF)
option(SODIUM_UPDATE_SUBMODULES "Update submodules during build" ON)
option(SODIUM_FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
# Subdirectories
add_subdirectory(src)
if (SODIUM_BUILD_BENCHMARKS)
message(STATUS "Building benchmarks...")
add_subdirectory(benchmarks)
endif ()
if (SODIUM_BUILD_DOC)
message(STATUS "Building documentation...")
add_subdirectory(documentation)
endif ()
if (SODIUM_BUILD_EXAMPLES)
message(STATUS "Building examples...")
add_subdirectory(examples)
endif ()
if (SODIUM_BUILD_TESTS)
message(STATUS "Building tests...")
add_subdirectory(tests)
endif ()
if (SODIUM_ENABLE_PCH)
message(STATUS "Precompiling headers...")
target_precompile_headers(
sodium PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/sodpch.hpp
)
else ()
message(STATUS "Precompiled headers disabled.")
endif ()
# Git submodule update
find_package(Git QUIET)
if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
if (SODIUM_UPDATE_SUBMODULES)
message(STATUS "Updating submodules...")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT
)
if (NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif ()
endif ()
endif ()
# Libraries
file(
GLOB LIB_DIRS
LIST_DIRECTORIES true
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/libs/*
)
foreach (DIR ${LIB_DIRS})
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${DIR}/CMakeLists.txt)
message(STATUS "Adding ${DIR}...")
add_subdirectory(${DIR})
endif ()
endforeach ()
# Preprocessor definitions
if (WIN32)
target_compile_definitions(
sodium
PUBLIC SOD_PLATFORM_WINDOWS
PUBLIC SOD_BUILD_DLL
)
endif ()