1 # Setup the project and settings
3 set(PROJECT_VERSION 3.5.0)
6 include(GNUInstallDirs)
9 # Sets build type if not set by now
10 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
12 set(default_build_type Debug)
14 message(WARNING "Default build type is not set (CMAKE_BUILD_TYPE)")
17 message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
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")
23 # Used as public API to be included into other projects
24 set(raylib_public_headers
32 # Sources to be compiled
42 # <root>/cmake/GlfwImport.cmake handles the details around the inclusion of glfw
47 MESSAGE(STATUS "Audio Backend: miniaudio")
48 list(APPEND raylib_sources raudio.c)
50 MESSAGE(STATUS "Audio Backend: None (-DUSE_AUDIO=OFF)")
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)
58 add_library(raylib ${raylib_sources} ${raylib_public_headers})
60 if (NOT BUILD_SHARED_LIBS)
61 MESSAGE(STATUS "Building raylib static library")
62 add_library(raylib_static ALIAS raylib)
64 MESSAGE(STATUS "Building raylib shared library")
66 target_compile_definitions(raylib
67 PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED>
68 INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED>
73 set_target_properties(raylib PROPERTIES
74 PUBLIC_HEADER "${raylib_public_headers}"
75 VERSION ${PROJECT_VERSION}
76 SOVERSION ${API_VERSION}
79 if (WITH_PIC OR BUILD_SHARED_LIBS)
80 set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON)
83 target_link_libraries(raylib "${LIBS_PRIVATE}")
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)
90 # Registering include directories
91 target_include_directories(raylib
93 $<INSTALL_INTERFACE:include>
94 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
96 ${CMAKE_CURRENT_SOURCE_DIR}
101 # Copy the header files to the build directory for convenience
102 file(COPY ${raylib_public_headers} DESTINATION "include")
104 # Includes information on how the library will be installed on the system
105 # when cmake --install is run
106 include(InstallConfigurations)
108 # Print the flags for the user
109 if (DEFINED CMAKE_BUILD_TYPE)
110 message(STATUS "Generated build type: ${CMAKE_BUILD_TYPE}")
112 message(STATUS "Generated config types: ${CMAKE_CONFIGURATION_TYPES}")
115 message(STATUS "Compiling with the flags:")
116 message(STATUS " PLATFORM=" ${PLATFORM_CPP})
117 message(STATUS " GRAPHICS=" ${GRAPHICS})
119 # Options if you want to create an installer using CPack
120 include(PackConfigurations)