-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
172 lines (137 loc) · 4.57 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
cmake_minimum_required(VERSION 3.26)
project(csharpify
VERSION 1.1
DESCRIPTION "Package and example of how to embed C# in C++ applications."
)
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(CSharpifyDefinitions)
include(CSharpifyDotnet)
add_subdirectory(dotnet-deps)
# Yes, this is included twice. It's on purpose, so it can finish setting up defined after the dotnet-deps restore is done.
include(CSharpifyDotnet)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if(DOTNET_PLATFORM STREQUAL "osx")
find_library(IOKIT IOKit)
find_library(COCOA Cocoa)
find_library(COREVIDEO CoreVideo)
elseif(DOTNET_PLATFORM STREQUAL "win")
# There is also the possibility of downloading pre-packaged source release instead of
# grabbing the git tag.
set(BUILD_SDL2 1)
elseif(DOTNET_PLATFORM STREQUAL "linux")
# We could consume an existing package, but we can also just build our own
# and not require extra steps to make this work.
set(BUILD_SDL2 1)
endif()
if(BUILD_SDL2)
set(SDL2_DISABLE_SDL2MAIN 1)
set(SDL_TEST 0)
set(BUILD_SHARED_LIBS 0)
set(SDL_VULKAN 1)
set(SDL_DIRECTX 0)
include(FetchContent)
FetchContent_Declare(
sdl2
GIT_REPOSITORY https://github.com/libsdl-org/SDL
GIT_TAG SDL2
)
FetchContent_MakeAvailable(sdl2)
elseif(DOTNET_PLATFORM STREQUAL "win")
include(FetchContent)
FetchContent_Declare(
sdl2
URL https://github.com/libsdl-org/SDL/releases/download/release-2.30.0/SDL2-devel-2.30.0-VC.zip
URL_HASH MD5=179d5f19c62c16343a3bd606ea5b121a
)
FetchContent_MakeAvailable(sdl2)
list(APPEND CMAKE_PREFIX_PATH "${sdl2_SOURCE_DIR}")
set(HAVE_SDL2_PACKAGE 1)
else()
set(HAVE_SDL2_PACKAGE 1)
endif()
if(HAVE_SDL2_PACKAGE)
find_package(SDL2 REQUIRED)
endif()
if(DOTNET_PLATFORM STREQUAL "osx" OR DOTNET_PLATFORM STREQUAL "ios")
set(USE_MOLTENVK 1)
endif()
if(USE_MOLTENVK)
find_package(Vulkan REQUIRED COMPONENTS MoltenVK)
else()
find_package(Vulkan REQUIRED)
set(Vulkan_MoltenVK_LIBRARY "")
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(STATUS "CMAKE_INSTALL_PREFIX is not set. Default value is '${CMAKE_INSTALL_PREFIX}', will set it to ${CMAKE_SOURCE_DIR}/install")
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "Where the library will be installed to" FORCE)
endif()
file(MAKE_DIRECTORY packages)
set(IMGUI_STATIC 0 CACHE BOOL "" FORCE)
set(IMGUI_OBJECT 1 CACHE BOOL "" FORCE)
add_subdirectory(managed)
add_subdirectory(native)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT csharpify)
install(TARGETS csharpify_coreclr EXPORT csharpify_coreclr_export
FILE_SET HEADERS DESTINATION include/csharpify/coreclr
)
install(TARGETS csharpify_mono EXPORT csharpify_mono_export
FILE_SET HEADERS DESTINATION include/csharpify/mono
)
install(DIRECTORY ${csharpify_native_SOURCE_DIR}/coreclr/ DESTINATION include/csharpify/coreclr
FILES_MATCHING PATTERN "*.cpp")
install(DIRECTORY ${csharpify_native_SOURCE_DIR}/mono/ DESTINATION include/csharpify/mono
FILES_MATCHING PATTERN "*.cpp")
install(EXPORT csharpify_coreclr_export
FILE CSharpifyCoreCLR.cmake
DESTINATION lib/cmake/csharpify
)
install(EXPORT csharpify_mono_export
FILE CSharpifyMono.cmake
DESTINATION lib/cmake/csharpify
)
install(FILES
cmake/CSharpifyDefinitions.cmake
cmake/CSharpifyDotnet.cmake
native/config.h.in
DESTINATION lib/cmake/csharpify
)
install(FILES
LICENSE
AUTHORS
DESTINATION "./"
)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/dotnet-deps/ DESTINATION lib/cmake/csharpify/dotnet-deps
FILES_MATCHING
PATTERN "*.csproj"
PATTERN "CMakeLists.txt"
PATTERN "*.props"
PATTERN "obj/*" EXCLUDE
)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/dotnet-deps/imports/ DESTINATION lib/cmake/csharpify/dotnet-deps/imports/
FILES_MATCHING
PATTERN "*.props"
)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/CSharpifyConfig.cmake"
INSTALL_DESTINATION lib/cmake/csharpify
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CSharpifyConfigVersion.cmake"
VERSION "${version}"
COMPATIBILITY AnyNewerVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/CSharpifyConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CSharpifyConfigVersion.cmake"
DESTINATION lib/cmake/csharpify
)
set(CPACK_SYSTEM_NAME "all")
include(CPack)