forked from vulkify/vulkify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
107 lines (84 loc) · 3.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
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
enable_language(CXX)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # don't let OPTION erase non-cache variables
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # enable PIC
set(CMAKE_DEBUG_POSTFIX "-d")
set(CMAKE_CXX_EXTENSIONS OFF) # disable compiler extensions
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Debug) # ensure CMAKE_BUILD_TYPE is not empty
endif()
# build version
include(cmake/build_version.cmake)
# project parameters
set(project_name vulkify)
set(${project_name}_version_file vulkify_version.hpp)
set(${project_name}_version ${build_version})
set(cxx_standard cxx_std_20)
project(${project_name} VERSION "${${project_name}_version}")
set(${project_name}_soversion ${PROJECT_VERSION_MAJOR})
set(is_root_project OFF) # indicate if this is the top-level project
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(is_root_project ON)
message(STATUS "${PROJECT_NAME} is top level")
endif()
# options
option(VULKIFY_BUILD_EXAMPLES "Build vulkify examples" ${is_root_project})
option(VULKIFY_DEBUG_TRACE "Enable debug trace messages" ${is_root_project})
option(VULKIFY_INSTALL "Install vulkify" ${is_root_project})
option(VULKIFY_USE_PCH "Enable PCH" ON)
# includes
include(CheckPIESupported)
check_pie_supported()
include(cmake/platform.cmake) # set up helper cache variables
# ktl
if(VULKIFY_INSTALL)
set(KTL_INSTALL ON)
if(NOT KTL_INSTALL)
message(WARNING "Invalid INSTALL flags")
endif()
endif()
include(FetchContent)
FetchContent_Declare(ktl
GIT_REPOSITORY https://github.com/karnkaul/ktl
GIT_TAG v1.4
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/src/ktl"
)
FetchContent_MakeAvailable(ktl)
# git operations
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
git_get_commit_hash(${PROJECT_NAME}_GIT_COMMIT_HASH) # store commit hash in ${PROJECT_NAME}_GIT_COMIT_HASH
endif()
# external
add_subdirectory(ext)
add_subdirectory(cmake/interface) # import interface library
# header text
if(is_root_project)
set(build_config ${CMAKE_BUILD_TYPE})
if(CMAKE_CONFIGURATION_TYPES)
set(build_config "Multi-config")
endif()
message(STATUS "[${CMAKE_SYSTEM_PROCESSOR}] [${PLATFORM}] [${CMAKE_GENERATOR}] [${CMAKE_CXX_COMPILER_ID}] [${build_config}]")
endif()
# compile commands
if(is_root_project AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
message(STATUS "Exporting compile commands")
endif()
# library
add_subdirectory(vulkify)
# examples
if(VULKIFY_BUILD_EXAMPLES)
message(STATUS "Adding vulkify examples to build tree")
add_subdirectory(examples)
enable_testing()
message(STATUS "Adding vulkify test target")
add_test(NAME vulkify-headless COMMAND ${PROJECT_NAME}-quick-start --headless)
endif()
if(VULKIFY_INSTALL)
install_package_config(PACKAGE ${PROJECT_NAME} IN vulkify/config.cmake.in)
install_package_version(PACKAGE ${PROJECT_NAME} VERSION ${${PROJECT_NAME}_version})
export_package_to_build_tree(PACKAGE ${PROJECT_NAME})
endif()