generated from asmaloney/GDExtensionTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
122 lines (94 loc) · 3.28 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
# SPDX-License-Identifier: Unlicense
cmake_minimum_required( VERSION 3.22 )
message( STATUS "Using CMake ${CMAKE_VERSION}" )
# 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(swbf2
LANGUAGES
CXX
VERSION
0.1.0
)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
# 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("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(LIB_ARCH "x86_64")
else()
set(LIB_ARCH "x86")
endif()
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 ${PROJECT_NAME}/bin
set( INSTALL_DIR "project/bin" )
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "" FORCE)
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 )
set( GODOT_CPP_SYSTEM_HEADERS ON CACHE BOOL "" FORCE )
add_subdirectory(extern)
target_link_libraries( ${PROJECT_NAME}
PRIVATE
godot-cpp
lua
)