Debian Codegraph @

src/CMakeLists.txt

raw
1 # Setup the project and settings
2 project(raylib C)
3 set(PROJECT_VERSION 6.0.0)
4 set(API_VERSION 600)
5
6 include(GNUInstallDirs)
7 include(JoinPaths)
8
9 # Sets build type if not set by now
10 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
11 if(PROJECT_IS_TOP_LEVEL)
12 set(default_build_type Debug)
13 else()
14 message(WARNING "Default build type is not set (CMAKE_BUILD_TYPE)")
15 endif()
16
17 message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
18
19 set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
20 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
21 endif()
22
23 # Used as public API to be included into other projects
24 set(raylib_public_headers
25 raylib.h
26 rcamera.h
27 rlgl.h
28 raymath.h
29 )
30
31 # Sources to be compiled
32 set(raylib_sources
33 raudio.c
34 rcore.c
35 rmodels.c
36 rshapes.c
37 rtext.c
38 rtextures.c
39 )
40
41 # <root>/cmake/GlfwImport.cmake handles the details around the inclusion of glfw
42 if (NOT ${PLATFORM} MATCHES "Web")
43 include(GlfwImport)
44 endif ()
45
46 # Sets additional platform options and link libraries for each platform
47 # also selects the proper graphics API and version for that platform
48 # Produces a variable LIBS_PRIVATE that will be used later
49 include(LibraryConfigurations)
50
51 if (SUPPORT_MODULE_RAUDIO)
52 MESSAGE(STATUS "Audio Backend: miniaudio")
53 else ()
54 MESSAGE(STATUS "Audio Backend: None (-DCUSTOMIZE_BUILD=ON -DSUPPORT_MODULE_RAUDIO=OFF)")
55 endif ()
56
57 add_library(raylib ${raylib_sources} ${raylib_public_headers})
58
59 if (NOT BUILD_SHARED_LIBS)
60 MESSAGE(STATUS "Building raylib static library")
61 add_library(raylib_static ALIAS raylib)
62 else()
63 MESSAGE(STATUS "Building raylib shared library")
64 target_compile_definitions(raylib
65 PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED>
66 INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED>
67 )
68 endif()
69
70 if (${PLATFORM} MATCHES "Web")
71 target_link_options(raylib PUBLIC "-sUSE_GLFW=3" -sEXPORTED_RUNTIME_METHODS=ccall)
72 if(${GRAPHICS} MATCHES "GRAPHICS_API_OPENGL_ES3")
73 target_link_options(raylib PUBLIC "-sMIN_WEBGL_VERSION=2")
74 target_link_options(raylib PUBLIC "-sMAX_WEBGL_VERSION=2")
75 endif()
76 endif()
77
78 if (${PLATFORM} MATCHES "Android")
79 # Wrap fopen at link time so all code (including third-party libs) goes
80 # through __wrap_fopen, which handles Android APK asset loading
81 target_link_options(raylib PUBLIC -Wl,--wrap=fopen)
82 endif()
83
84 set_target_properties(raylib PROPERTIES
85 PUBLIC_HEADER "${raylib_public_headers}"
86 VERSION ${PROJECT_VERSION}
87 SOVERSION ${API_VERSION}
88 )
89
90 if (WITH_PIC OR BUILD_SHARED_LIBS)
91 set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON)
92 endif ()
93
94 if (BUILD_SHARED_LIBS)
95 # Hide raylib's symbols by default so RLAPI can expose them
96 set_property(TARGET raylib PROPERTY C_VISIBILITY_PRESET hidden)
97 endif ()
98
99 target_link_libraries(raylib PRIVATE $<BUILD_INTERFACE:${LIBS_PRIVATE}>)
100 target_link_libraries(raylib PUBLIC ${LIBS_PUBLIC})
101
102 # Sets some compile time definitions for the pre-processor
103 # If CUSTOMIZE_BUILD option is on you will not use config.h by default
104 # and you will be able to select more build options
105 include(CompileDefinitions)
106
107 # Registering include directories
108 target_include_directories(raylib
109 PUBLIC
110 $<INSTALL_INTERFACE:include>
111 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
112 PRIVATE
113 ${CMAKE_CURRENT_SOURCE_DIR}
114 ${OPENGL_INCLUDE_DIR}
115 ${OPENAL_INCLUDE_DIR}
116 )
117
118 # Copy the header files to the build directory for convenience
119 file(COPY ${raylib_public_headers} DESTINATION "include")
120 if (PLATFORM STREQUAL "Desktop")
121 if (UNIX AND NOT APPLE)
122 if (GLFW_BUILD_X11)
123 find_package(X11 REQUIRED)
124
125 target_compile_definitions(raylib PRIVATE _GLFW_X11)
126
127 target_link_libraries(raylib PRIVATE
128 ${X11_LIBRARIES}
129 )
130
131 message(STATUS "X11 support enabled for raylib")
132 endif()
133 endif()
134 endif()
135
136 # Includes information on how the library will be installed on the system
137 # when cmake --install is run
138 include(InstallConfigurations)
139
140 # Print the flags for the user
141 if (DEFINED CMAKE_BUILD_TYPE)
142 message(STATUS "Generated build type: ${CMAKE_BUILD_TYPE}")
143 else ()
144 message(STATUS "Generated config types: ${CMAKE_CONFIGURATION_TYPES}")
145 endif ()
146
147 message(STATUS "Compiling with the flags:")
148 message(STATUS " PLATFORM=" ${PLATFORM_CPP})
149 message(STATUS " GRAPHICS=" ${GRAPHICS})
150
151 # Options if you want to create an installer using CPack
152 include(PackConfigurations)
153
154 enable_testing()