-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
176 lines (141 loc) · 4.75 KB
/
Copy pathCMakeLists.txt
File metadata and controls
176 lines (141 loc) · 4.75 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
cmake_minimum_required(VERSION 3.14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 17)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
endif()
endif()
message( STATUS "Using CMake ${CMAKE_VERSION}" )
if( "${Engine}" STREQUAL "Godot" )
add_compile_definitions(GODOT)
elseif( "${Engine}" STREQUAL "Unity" )
add_compile_definitions(UNITY)
elseif( "${Engine}" STREQUAL "Unreal" )
add_compile_definitions(UNREAL)
else()
add_compile_definitions(NATIVE)
endif()
# 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/" )
# Enable some option for compiler
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()
# Ignore PCL errors in Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-gnu-anonymous-struct -Wno-nested-anon-types)
endif()
# 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 )
set_property(GLOBAL PROPERTY USE_FOLDERS 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
if( "${Engine}" STREQUAL "Godot" )
project( GDExtensionTemplate
LANGUAGES
CXX
VERSION
0.1.0
)
elseif( "${Engine}" STREQUAL "Unity" )
project( UnityExtensionTemplate
LANGUAGES
CXX
VERSION
0.1.0
)
elseif( "${Engine}" STREQUAL "Unreal" )
project( UnrealExtensionTemplate
LANGUAGES
CXX
VERSION
0.1.0
)
elseif( "${Engine}" STREQUAL "Native" )
project( NativeExtensionTemplate
LANGUAGES
CXX
VERSION
0.1.0
)
endif()
# Create our library
add_library( ${PROJECT_NAME} SHARED )
# 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()
# Warnings
# include( CompilerWarnings )
# Create and include version info file from git
include( GitVersionInfo )
add_subdirectory( src )
# Install library and extension file in ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}
set( INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/" )
message( STATUS "Install directory: ${INSTALL_DIR}")
if(POLICY CMP0177)
cmake_policy(SET CMP0177 NEW)
endif()
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
if( "${Engine}" STREQUAL "Godot" )
# From here: https://github.com/godotengine/godot-cpp
if ( NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/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( 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
)
endif()