]> git.sesse.net Git - pistorm/blob - raylib/CMakeLists.txt
[MEGA-WIP] Raylib-based RTG output
[pistorm] / raylib / CMakeLists.txt
1 # Setup the project and settings
2 project(raylib C)
3 set(PROJECT_VERSION 3.5.0)
4 set(API_VERSION 351)
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(RAYLIB_IS_MAIN)
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     rlgl.h
27     physac.h
28     raymath.h
29     raudio.h
30     )
31
32 # Sources to be compiled
33 set(raylib_sources
34     core.c
35     models.c
36     shapes.c
37     text.c
38     textures.c
39     utils.c
40     )
41
42 # <root>/cmake/GlfwImport.cmake handles the details around the inclusion of glfw
43 include(GlfwImport)
44
45
46 if (USE_AUDIO)
47     MESSAGE(STATUS "Audio Backend: miniaudio")
48     list(APPEND raylib_sources raudio.c)
49 else ()
50     MESSAGE(STATUS "Audio Backend: None (-DUSE_AUDIO=OFF)")
51 endif ()
52
53 # Sets additional platform options and link libraries for each platform
54 # also selects the proper graphics API and version for that platform
55 # Produces a variable LIBS_PRIVATE that will be used later
56 include(LibraryConfigurations)
57
58 add_library(raylib ${raylib_sources} ${raylib_public_headers})
59
60 if (NOT BUILD_SHARED_LIBS)
61     MESSAGE(STATUS "Building raylib static library")
62     add_library(raylib_static ALIAS raylib)
63 else()
64     MESSAGE(STATUS "Building raylib shared library")
65     if (MSVC)
66         target_compile_definitions(raylib
67                                    PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED>
68                                    INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED>
69                                    )
70     endif ()
71 endif()
72
73 set_target_properties(raylib PROPERTIES
74                       PUBLIC_HEADER "${raylib_public_headers}"
75                       VERSION ${PROJECT_VERSION}
76                       SOVERSION ${API_VERSION}
77                       )
78
79 if (WITH_PIC OR BUILD_SHARED_LIBS)
80     set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON)
81 endif ()
82
83 target_link_libraries(raylib "${LIBS_PRIVATE}")
84
85 # Sets some compile time definitions for the pre-processor
86 # If CUSTOMIZE_BUILD option is on you will not use config.h by default
87 # and you will be able to select more build options
88 include(CompileDefinitions)
89
90 # Registering include directories
91 target_include_directories(raylib
92                            PUBLIC
93                            $<INSTALL_INTERFACE:include>
94                            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
95                            PRIVATE
96                            ${CMAKE_CURRENT_SOURCE_DIR}
97                            ${OPENGL_INCLUDE_DIR}
98                            ${OPENAL_INCLUDE_DIR}
99                            )
100
101 # Copy the header files to the build directory for convenience
102 file(COPY ${raylib_public_headers} DESTINATION "include")
103
104 # Includes information on how the library will be installed on the system
105 # when cmake --install is run
106 include(InstallConfigurations)
107
108 # Print the flags for the user
109 if (DEFINED CMAKE_BUILD_TYPE)
110     message(STATUS "Generated build type: ${CMAKE_BUILD_TYPE}")
111 else ()
112     message(STATUS "Generated config types: ${CMAKE_CONFIGURATION_TYPES}")
113 endif ()
114
115 message(STATUS "Compiling with the flags:")
116 message(STATUS "  PLATFORM=" ${PLATFORM_CPP})
117 message(STATUS "  GRAPHICS=" ${GRAPHICS})
118
119 # Options if you want to create an installer using CPack
120 include(PackConfigurations)
121
122 enable_testing()