You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 rivejä
6.4 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 -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
  87. # Since WASM is used, ALLOW_MEMORY_GROWTH has no extra overheads
  88. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 --no-heap-copy")
  89. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --shell-file ${CMAKE_SOURCE_DIR}/src/shell.html")
  90. set(CMAKE_EXECUTABLE_SUFFIX ".html")
  91. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/raylib_opengl_interop.c)
  92. # Remove the -rdynamic flag because otherwise emscripten
  93. # does not generate HTML+JS+WASM files, only a non-working
  94. # and fat HTML
  95. string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
  96. elseif ("${PLATFORM}" STREQUAL "DRM")
  97. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c)
  98. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/raylib_opengl_interop.c)
  99. endif ()
  100. include_directories(BEFORE SYSTEM others/external/include)
  101. if (NOT TARGET raylib)
  102. find_package(raylib 2.0 REQUIRED)
  103. endif ()
  104. # Do each example
  105. foreach (example_source ${example_sources})
  106. # Create the basename for the example
  107. get_filename_component(example_name ${example_source} NAME)
  108. string(REPLACE ".c" "" example_name ${example_name})
  109. # Setup the example
  110. add_executable(${example_name} ${example_source})
  111. target_link_libraries(${example_name} raylib)
  112. string(REGEX MATCH ".*/.*/" resources_dir ${example_source})
  113. string(APPEND resources_dir "resources")
  114. if (${PLATFORM} MATCHES "Web" AND EXISTS ${resources_dir})
  115. # The local resources path needs to be mapped to /resources virtual path
  116. string(APPEND resources_dir "@resources")
  117. set_target_properties(${example_name} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}")
  118. endif ()
  119. endforeach ()
  120. # Copy all of the resource files to the destination
  121. file(COPY ${example_resources} DESTINATION "resources/")