forked from asmaloney/GDExtensionTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
142 lines (109 loc) · 3.95 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
# SPDX-License-Identifier: Unlicense
cmake_minimum_required( VERSION 3.22 )
message( STATUS "Using CMake ${CMAKE_VERSION}" )
# Require out-of-source builds
file( TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH )
if ( EXISTS "${LOC_PATH}" )
message( FATAL_ERROR "You cannot build in the source directory. Please use a build subdirectory." )
endif()
# Add paths to modules
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" )
# Turn on link time optimization for everything
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON )
# Output compile commands to compile_commands.json (for debugging CMake issues)
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
# Build universal lib on macOS
# Note that CMAKE_OSX_ARCHITECTURES must be set before project().
if ( APPLE )
set( CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" )
endif()
# Main project information
project( GDExtensionTemplate
LANGUAGES
CXX
VERSION
0.1.0
)
# Create our library
add_library( ${PROJECT_NAME} SHARED )
target_compile_features( ${PROJECT_NAME}
PRIVATE
cxx_std_17
)
# LIB_ARCH is the architecture being built. It is set to the build system's architecture.
# For macOS, we build a universal library (both arm64 and x86_64).
set( LIB_ARCH ${CMAKE_SYSTEM_PROCESSOR} )
if ( APPLE )
set( LIB_ARCH "universal" )
endif()
# LIB_DIR is where the actual library ends up. This is used in both the build directory and the
# install directory and needs to be consistent with the paths in the gdextension file.
# e.g. linux.release.x86_64 = "lib/Linux-x86_64/libGDExtensionTemplate.so"
set( LIB_DIR "lib/${CMAKE_SYSTEM_NAME}-${LIB_ARCH}" )
message( STATUS "Building ${PROJECT_NAME} for ${LIB_ARCH} on ${CMAKE_SYSTEM_NAME}")
# BUILD_OUTPUT_DIR is where we put the resulting library (in the build directory)
set( BUILD_OUTPUT_DIR "${PROJECT_BINARY_DIR}/${PROJECT_NAME}/" )
set_target_properties( ${PROJECT_NAME}
PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN true
RUNTIME_OUTPUT_DIRECTORY "${BUILD_OUTPUT_DIR}/${LIB_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_DIR}/${LIB_DIR}"
)
if( NOT DEFINED CMAKE_DEBUG_POSTFIX )
set_target_properties( ${PROJECT_NAME}
PROPERTIES
DEBUG_POSTFIX "-d"
)
endif()
# Copy over additional files from the support_files directory
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/support_files"
${BUILD_OUTPUT_DIR}
)
# Warnings
include( CompilerWarnings )
# Create and include version info file from git
include( GitVersionInfo )
add_subdirectory( src )
# Install library, extension file, and support files in ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}
set( INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/" )
message( STATUS "Install directory: ${INSTALL_DIR}")
install( TARGETS ${PROJECT_NAME}
LIBRARY
DESTINATION ${INSTALL_DIR}/${LIB_DIR}
RUNTIME
DESTINATION ${INSTALL_DIR}/${LIB_DIR}
)
# Copy over support files
install( DIRECTORY "${CMAKE_SOURCE_DIR}/support_files/"
DESTINATION ${INSTALL_DIR}
PATTERN ".*" EXCLUDE
)
add_subdirectory( templates )
# ccache
# Turns on ccache if found
include( ccache )
# Formatting
# Adds a custom target to format all the code at once
include( ClangFormat )
# godot-cpp
# From here: https://github.com/godotengine/godot-cpp
if ( NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/extern/godot-cpp/Makefile" )
message(
FATAL_ERROR
"[${PROJECT_NAME}] The godot-cpp submodule was not downloaded. Please update submodules: git submodule update --init --recursive."
)
endif()
set( GODOT_CPP_SYSTEM_HEADERS ON CACHE BOOL "" FORCE )
add_subdirectory( extern/godot-cpp )
set_target_properties( godot-cpp
PROPERTIES
CXX_VISIBILITY_PRESET hidden # visibility needs to be the same as the main library
)
target_link_libraries( ${PROJECT_NAME}
PRIVATE
godot-cpp
)