-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
154 lines (123 loc) · 5.24 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# MIT License
# Copyright (c) 2022 Nathan V. Morrical
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.12)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
cmake_policy(SET CMP0104 NEW)
endif()
if (NOT (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}))
set(GPRT_IS_SUBPROJECT ON)
else()
set(GPRT_IS_SUBPROJECT OFF)
endif()
set(CMAKE_BUILD_TYPE_INIT "Release")
# project command is required to come after cmake_minimum_required command.
project(GPRT VERSION 1.0.0 LANGUAGES C CXX)
# Check if the generator is set to generate 64-bit code
include(CheckTypeSize)
check_type_size("void*" SIZEOF_VOID_P)
if(NOT SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "A 64-bit compiler is required.")
endif()
if (NOT GPRT_IS_SUBPROJECT)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
# ------------------------------------------------------------------
# Configuration Options
# ------------------------------------------------------------------
option(GPRT_BUILD_SHARED "Build GPRT as a shared library? (otherwise static)" OFF)
set(BUILD_SHARED_LIBS ${GPRT_BUILD_SHARED}) # use 'GPRT_' naming convention
option(GPRT_USE_INCLUDED_GLFW "Build GPRT including the submoduled GLFW? (otherwise, system GLFW will be found)" ON)
# ------------------------------------------------------------------
# External configuration variables
# ------------------------------------------------------------------
# provide these varaibles at both a local and parent scope
if (GPRT_IS_SUBPROJECT)
set(GPRT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gprt PARENT_SCOPE)
endif()
set(GPRT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gprt)
#===============================================================================
# Update git submodules as needed
#===============================================================================
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
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()
# ------------------------------------------------------------------
# first, include some dependencies
# ------------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/gprt/cmake/")
if (GPRT_IS_SUBPROJECT)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (GPRT_BUILD_SHARED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if (NOT GPRT_IS_SUBPROJECT)
option(GPRT_BUILD_SAMPLES "Build the Samples?" ON)
option(GPRT_BUILD_TESTS "Build the Test Code?" OFF)
option(BUILD_DOC "Build documentation" OFF)
endif()
add_subdirectory(3rdParty)
# ------------------------------------------------------------------
# gprt library itself
# ------------------------------------------------------------------
add_subdirectory(gprt)
# ------------------------------------------------------------------
# tutorial/samples
# ------------------------------------------------------------------
if (GPRT_BUILD_SAMPLES)
add_subdirectory(samples)
endif()
if (GPRT_BUILD_TESTS)
add_subdirectory(tests)
endif()
if (GPRT_IS_SUBPROJECT)
return()
endif()
# ------------------------------------------------------------------
# documentation
# ------------------------------------------------------------------
if (BUILD_DOC)
add_subdirectory(docs)
endif()
# include(CTest)
# if (BUILD_TESTING)
# enable_testing()
# endif()
# # ------------------------------------------------------------------
# # some basic testing
# # ------------------------------------------------------------------
# if (GPRT_BUILD_ADVANCED_TESTS)
# add_subdirectory(tests)
# endif()