CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # Setup the project and settings
  2. project(raylib C)
  3. set(PROJECT_VERSION 3.5.0)
  4. set(API_VERSION 351)
  5. include(GNUInstallDirs)
  6. include(JoinPaths)
  7. # Sets build type if not set by now
  8. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  9. if(RAYLIB_IS_MAIN)
  10. set(default_build_type Debug)
  11. else()
  12. message(WARNING "Default build type is not set (CMAKE_BUILD_TYPE)")
  13. endif()
  14. message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
  15. set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
  16. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  17. endif()
  18. # Used as public API to be included into other projects
  19. set(raylib_public_headers
  20. raylib.h
  21. rlgl.h
  22. physac.h
  23. raymath.h
  24. raudio.h
  25. )
  26. # Sources to be compiled
  27. set(raylib_sources
  28. core.c
  29. models.c
  30. shapes.c
  31. text.c
  32. textures.c
  33. utils.c
  34. )
  35. # <root>/cmake/GlfwImport.cmake handles the details around the inclusion of glfw
  36. include(GlfwImport)
  37. if (USE_AUDIO)
  38. MESSAGE(STATUS "Audio Backend: miniaudio")
  39. list(APPEND raylib_sources raudio.c)
  40. else ()
  41. MESSAGE(STATUS "Audio Backend: None (-DUSE_AUDIO=OFF)")
  42. endif ()
  43. # Sets additional platform options and link libraries for each platform
  44. # also selects the proper graphics API and version for that platform
  45. # Produces a variable LIBS_PRIVATE that will be used later
  46. include(LibraryConfigurations)
  47. add_library(raylib ${raylib_sources} ${raylib_public_headers})
  48. if (NOT BUILD_SHARED_LIBS)
  49. MESSAGE(STATUS "Building raylib static library")
  50. add_library(raylib_static ALIAS raylib)
  51. else()
  52. MESSAGE(STATUS "Building raylib shared library")
  53. if (MSVC)
  54. target_compile_definitions(raylib
  55. PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED>
  56. INTERFACE $<INSTALL_INTERFACE:USE_LIBTYPE_SHARED>
  57. )
  58. endif ()
  59. endif()
  60. set_target_properties(raylib PROPERTIES
  61. PUBLIC_HEADER "${raylib_public_headers}"
  62. VERSION ${PROJECT_VERSION}
  63. SOVERSION ${API_VERSION}
  64. )
  65. if (WITH_PIC OR BUILD_SHARED_LIBS)
  66. set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON)
  67. endif ()
  68. target_link_libraries(raylib "${LIBS_PRIVATE}")
  69. # Sets some compile time definitions for the pre-processor
  70. # If CUSTOMIZE_BUILD option is on you will not use config.h by default
  71. # and you will be able to select more build options
  72. include(CompileDefinitions)
  73. # Registering include directories
  74. target_include_directories(raylib
  75. PUBLIC
  76. $<INSTALL_INTERFACE:include>
  77. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  78. PRIVATE
  79. ${CMAKE_CURRENT_SOURCE_DIR}
  80. ${OPENGL_INCLUDE_DIR}
  81. ${OPENAL_INCLUDE_DIR}
  82. )
  83. # Copy the header files to the build directory for convenience
  84. file(COPY ${raylib_public_headers} DESTINATION "include")
  85. # Includes information on how the library will be installed on the system
  86. # when cmake --install is run
  87. include(InstallConfigurations)
  88. # Print the flags for the user
  89. if (DEFINED CMAKE_BUILD_TYPE)
  90. message(STATUS "Generated build type: ${CMAKE_BUILD_TYPE}")
  91. else ()
  92. message(STATUS "Generated config types: ${CMAKE_CONFIGURATION_TYPES}")
  93. endif ()
  94. message(STATUS "Compiling with the flags:")
  95. message(STATUS " PLATFORM=" ${PLATFORM_CPP})
  96. message(STATUS " GRAPHICS=" ${GRAPHICS})
  97. # Options if you want to create an installer using CPack
  98. include(PackConfigurations)
  99. enable_testing()