CMakeLists.txt (4250B)
1 # Setup the project and settings 2 project(raylib C) 3 set(PROJECT_VERSION 5.5.0) 4 set(API_VERSION 550) 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 raymath.h 28 ) 29 30 # Sources to be compiled 31 set(raylib_sources 32 raudio.c 33 rcore.c 34 rmodels.c 35 rshapes.c 36 rtext.c 37 rtextures.c 38 utils.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") 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 set_target_properties(raylib PROPERTIES 79 PUBLIC_HEADER "${raylib_public_headers}" 80 VERSION ${PROJECT_VERSION} 81 SOVERSION ${API_VERSION} 82 ) 83 84 if (WITH_PIC OR BUILD_SHARED_LIBS) 85 set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON) 86 endif () 87 88 if (BUILD_SHARED_LIBS) 89 # Hide raylib's symbols by default so RLAPI can expose them 90 set_property(TARGET raylib PROPERTY C_VISIBILITY_PRESET hidden) 91 endif () 92 93 target_link_libraries(raylib "${LIBS_PRIVATE}") 94 95 # Sets some compile time definitions for the pre-processor 96 # If CUSTOMIZE_BUILD option is on you will not use config.h by default 97 # and you will be able to select more build options 98 include(CompileDefinitions) 99 100 # Registering include directories 101 target_include_directories(raylib 102 PUBLIC 103 $<INSTALL_INTERFACE:include> 104 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> 105 PRIVATE 106 ${CMAKE_CURRENT_SOURCE_DIR} 107 ${OPENGL_INCLUDE_DIR} 108 ${OPENAL_INCLUDE_DIR} 109 ) 110 111 # Copy the header files to the build directory for convenience 112 file(COPY ${raylib_public_headers} DESTINATION "include") 113 114 # Includes information on how the library will be installed on the system 115 # when cmake --install is run 116 include(InstallConfigurations) 117 118 # Print the flags for the user 119 if (DEFINED CMAKE_BUILD_TYPE) 120 message(STATUS "Generated build type: ${CMAKE_BUILD_TYPE}") 121 else () 122 message(STATUS "Generated config types: ${CMAKE_CONFIGURATION_TYPES}") 123 endif () 124 125 message(STATUS "Compiling with the flags:") 126 message(STATUS " PLATFORM=" ${PLATFORM_CPP}) 127 message(STATUS " GRAPHICS=" ${GRAPHICS}) 128 129 # Options if you want to create an installer using CPack 130 include(PackConfigurations) 131 132 enable_testing()