forked from gosu/gosu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
140 lines (107 loc) · 4.42 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
# Structure inspired by https://github.com/pabloariasal/modern-cmake-sample
# Assumptions:
# - We cannot go higher than CMake 3.10 while we support Ubuntu 18.04.
# - Prefer static libraries. Users should link Gosu into their games.
# - This is not (yet?) going to be used for building Ruby/Gosu.
# - This is not (yet?) going to replace the Visual Studio project for Windows.
cmake_minimum_required(VERSION 3.10...3.18.4)
project(Gosu VERSION 1.4.3)
##############################################
# Global options
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
##############################################
# Declare dependencies
find_package(SDL2 REQUIRED)
find_package(OpenGL REQUIRED)
if(APPLE)
find_library(COCOA_LIBRARY Cocoa)
find_library(AUDIO_TOOLBOX_LIBRARY AudioToolbox)
find_library(CORE_TEXT_LIBRARY CoreText)
find_library(ICONV_LIBRARY iconv)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
endif()
##############################################
# Create target and set properties
file(GLOB_RECURSE C_FILES ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/*.c)
file(GLOB HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/Gosu/*.hpp)
file(GLOB SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
# Build Gosu as a shared library only for now. This also means we don't have to
# find all of our dependencies again in cmake/GosuConfig.cmake.in, as the
# compiled .so/.dylib file will already reference them.
add_library(gosu SHARED ${C_FILES} ${HEADER_FILES} ${SOURCE_FILES})
# Ignore deprecation warnings from within Gosu while compiling Gosu itself.
set_target_properties(gosu PROPERTIES
COMPILE_DEFINITIONS "GOSU_DEPRECATED=")
# Compile all C++ files as Objective-C++ on macOS so that we can use ObjC APIs.
if(APPLE)
set_source_files_properties(${SOURCE_FILES} PROPERTIES
COMPILE_FLAGS "-x objective-c++")
endif()
target_include_directories(gosu
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
# Use target_include_directories(... SYSTEM ...) to suppress warnings in these headers.
target_include_directories(gosu SYSTEM
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/dependencies/mojoAL
${CMAKE_CURRENT_SOURCE_DIR}/dependencies/SDL_sound
${CMAKE_CURRENT_SOURCE_DIR}/dependencies/stb
${CMAKE_CURRENT_SOURCE_DIR}/dependencies/utf8proc
${SDL2_INCLUDE_DIRS})
target_link_libraries(gosu
PRIVATE
# The SDL2::SDL2 target is not available on Ubuntu 18.04.
${SDL2_LIBRARIES}
OpenGL::GL
# Only defined on macOS
${COCOA_LIBRARY}
${AUDIO_TOOLBOX_LIBRARY}
${CORE_TEXT_LIBRARY}
${ICONV_LIBRARY}
# Only defined on Linux
${FONTCONFIG_LIBRARIES})
##############################################
# Installation instructions
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Gosu)
install(TARGETS gosu
EXPORT gosu-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Copied from modern-cmake-sample, although the purpose is not clear to me.
set_target_properties(gosu PROPERTIES EXPORT_NAME Gosu)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Export the targets to a script
install(EXPORT gosu-targets
FILE
GosuTargets.cmake
NAMESPACE
Gosu::
DESTINATION
${INSTALL_CONFIGDIR})
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/GosuConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/GosuConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/GosuConfig.cmake
DESTINATION ${INSTALL_CONFIGDIR})
export(EXPORT gosu-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/GosuTargets.cmake
NAMESPACE Gosu::)
##############################################
# FFI interface, examples, and tests
# Alias our library as Gosu::Gosu so that examples and submodules can depend
# on it by its normal name.
add_library(Gosu::Gosu ALIAS gosu)
# Only build the FFI interface, examples, and tests if this is the top-level CMake module.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_subdirectory(ffi)
add_subdirectory(examples)
# If GoogleTest is not available as a CMake module, this is a no-op.
add_subdirectory(test)
endif()