Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

161 lignes
7.1 KiB

  1. # Setup the project and settings
  2. project(examples)
  3. # Directories that contain examples
  4. set(example_dirs
  5. audio
  6. core
  7. models
  8. others
  9. shaders
  10. shapes
  11. text
  12. textures
  13. )
  14. # Next few lines will check for existence of symbols or header files
  15. # They are needed for the physac example and threads examples
  16. set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=199309L)
  17. include(CheckSymbolExists)
  18. check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC)
  19. check_symbol_exists(QueryPerformanceCounter windows.h HAVE_QPC)
  20. set(CMAKE_REQUIRED_DEFINITIONS)
  21. if (HAVE_QPC OR HAVE_CLOCK_MONOTONIC)
  22. set(example_dirs ${example_dirs} physac)
  23. endif ()
  24. include(CheckIncludeFile)
  25. CHECK_INCLUDE_FILE("stdatomic.h" HAVE_STDATOMIC_H)
  26. set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  27. find_package(Threads)
  28. if (CMAKE_USE_PTHREADS_INIT AND HAVE_STDATOMIC_H)
  29. add_if_flag_compiles("-std=c11" CMAKE_C_FLAGS)
  30. if (THREADS_HAVE_PTHREAD_ARG)
  31. add_if_flag_compiles("-pthread" CMAKE_C_FLAGS)
  32. endif ()
  33. if (CMAKE_THREAD_LIBS_INIT)
  34. link_libraries("${CMAKE_THREAD_LIBS_INIT}")
  35. endif ()
  36. endif ()
  37. if (APPLE AND NOT CMAKE_SYSTEM STRLESS "Darwin-18.0.0")
  38. add_definitions(-DGL_SILENCE_DEPRECATION)
  39. MESSAGE(AUTHOR_WARNING "OpenGL is deprecated starting with macOS 10.14 (Mojave)!")
  40. endif ()
  41. # Collect all source files and resource files
  42. # into a CMake variable
  43. set(example_sources)
  44. set(example_resources)
  45. foreach (example_dir ${example_dirs})
  46. # Get the .c files
  47. file(GLOB sources ${example_dir}/*.c)
  48. list(APPEND example_sources ${sources})
  49. # Any any resources
  50. file(GLOB resources ${example_dir}/resources/*)
  51. list(APPEND example_resources ${resources})
  52. endforeach ()
  53. if(NOT CMAKE_USE_PTHREADS_INIT OR NOT HAVE_STDATOMIC_H)
  54. # Items requiring pthreads
  55. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_loading_thread.c)
  56. endif ()
  57. if (${PLATFORM} MATCHES "Android")
  58. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c)
  59. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/standard_lighting.c)
  60. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_picking.c)
  61. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_vr_simulator.c)
  62. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_camera_free.c)
  63. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_camera_first_person.c)
  64. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_world_screen.c)
  65. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_picking.c)
  66. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_cubicmap.c)
  67. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_skybox.c)
  68. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_picking.c)
  69. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_generation.c)
  70. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_heightmap.c)
  71. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_billboard.c)
  72. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_rlgl_solar_system.c)
  73. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_rlgl_full_solar_system.c)
  74. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_solar_system.c)
  75. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_obj_viewer.c)
  76. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_animation.c)
  77. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_first_person_maze.c)
  78. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_magicavoxel_loading.c)
  79. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_custom_uniform.c)
  80. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_model_shader.c)
  81. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_postprocessing.c)
  82. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_raymarching.c)
  83. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_palette_switch.c)
  84. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_basic_lighting.c)
  85. elseif (${PLATFORM} MATCHES "Web")
  86. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os")
  87. # Since WASM is used, ALLOW_MEMORY_GROWTH has no extra overheads
  88. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s WASM=1 -s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1 --shell-file ${CMAKE_SOURCE_DIR}/src/shell.html")
  89. set(CMAKE_EXECUTABLE_SUFFIX ".html")
  90. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/raylib_opengl_interop.c)
  91. # Remove the -rdynamic flag because otherwise emscripten
  92. # does not generate HTML+JS+WASM files, only a non-working
  93. # and fat HTML
  94. string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
  95. elseif ("${PLATFORM}" STREQUAL "DRM")
  96. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c)
  97. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/raylib_opengl_interop.c)
  98. elseif (NOT SUPPORT_GESTURES_SYSTEM)
  99. # Items requiring gestures system
  100. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/textures/textures_mouse_painting.c)
  101. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_basic_screen_manager.c)
  102. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_input_gestures_web.c)
  103. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_input_gestures.c)
  104. endif ()
  105. # The rlgl_standalone example only targets desktop, without shared libraries.
  106. if (BUILD_SHARED_LIBS OR NOT ${PLATFORM} MATCHES "Desktop")
  107. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c)
  108. endif()
  109. include_directories(BEFORE SYSTEM others/external/include)
  110. if (NOT TARGET raylib)
  111. find_package(raylib 2.0 REQUIRED)
  112. endif ()
  113. # Do each example
  114. foreach (example_source ${example_sources})
  115. # Create the basename for the example
  116. get_filename_component(example_name ${example_source} NAME)
  117. string(REPLACE ".c" "" example_name ${example_name})
  118. # Setup the example
  119. add_executable(${example_name} ${example_source})
  120. target_link_libraries(${example_name} raylib)
  121. if (NOT WIN32)
  122. target_link_libraries(${example_name} m)
  123. endif()
  124. string(REGEX MATCH ".*/.*/" resources_dir ${example_source})
  125. string(APPEND resources_dir "resources")
  126. if (${PLATFORM} MATCHES "Web" AND EXISTS ${resources_dir})
  127. # The local resources path needs to be mapped to /resources virtual path
  128. string(APPEND resources_dir "@resources")
  129. set_target_properties(${example_name} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}")
  130. endif ()
  131. endforeach ()
  132. # Copy all of the resource files to the destination
  133. file(COPY ${example_resources} DESTINATION "resources/")