Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

135 řádky
6.1 KiB

před 6 roky
před 6 roky
  1. # Setup the project and settings
  2. project(examples)
  3. # Get the sources together
  4. set(example_dirs audio core models others shaders shapes text textures)
  5. set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=199309L)
  6. include(CheckSymbolExists)
  7. check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC)
  8. check_symbol_exists(QueryPerformanceCounter windows.h HAVE_QPC)
  9. set(CMAKE_REQUIRED_DEFINITIONS)
  10. if(HAVE_QPC OR HAVE_CLOCK_MONOTONIC)
  11. set(example_dirs ${example_dirs} physac)
  12. endif()
  13. set(example_sources)
  14. set(example_resources)
  15. foreach(example_dir ${example_dirs})
  16. # Get the .c files
  17. file(GLOB sources ${example_dir}/*.c)
  18. list(APPEND example_sources ${sources})
  19. # Any any resources
  20. file(GLOB resources ${example_dir}/resources/*)
  21. list(APPEND example_resources ${resources})
  22. endforeach()
  23. if (APPLE AND NOT CMAKE_SYSTEM STRLESS "Darwin-18.0.0")
  24. add_definitions(-DGL_SILENCE_DEPRECATION)
  25. MESSAGE(AUTHOR_WARNING "OpenGL is deprecated starting with macOS 10.14 (Mojave)!")
  26. endif()
  27. set(OUTPUT_EXT)
  28. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c)
  29. include(CheckIncludeFile)
  30. CHECK_INCLUDE_FILE("stdatomic.h" HAVE_STDATOMIC_H)
  31. set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  32. find_package(Threads)
  33. if (CMAKE_USE_PTHREADS_INIT AND HAVE_STDATOMIC_H)
  34. add_if_flag_compiles("-std=c11" CMAKE_C_FLAGS)
  35. if(THREADS_HAVE_PTHREAD_ARG)
  36. add_if_flag_compiles("-pthread" CMAKE_C_FLAGS)
  37. endif()
  38. if(CMAKE_THREAD_LIBS_INIT)
  39. link_libraries("${CMAKE_THREAD_LIBS_INIT}")
  40. endif()
  41. else()
  42. # Items requiring pthreads
  43. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_loading_thread.c)
  44. endif()
  45. if(${PLATFORM} MATCHES "Android")
  46. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c)
  47. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/standard_lighting.c)
  48. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_picking.c)
  49. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_vr_simulator.c)
  50. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_camera_free.c)
  51. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_3d_camera_first_person.c)
  52. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_world_screen.c)
  53. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_picking.c)
  54. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_material_pbr.c)
  55. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_cubicmap.c)
  56. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_skybox.c)
  57. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_picking.c)
  58. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_mesh_generation.c)
  59. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_heightmap.c)
  60. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_billboard.c)
  61. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_rlgl_solar_system.c)
  62. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_rlgl_full_solar_system.c)
  63. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_solar_system.c)
  64. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_obj_viewer.c)
  65. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_animation.c)
  66. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/models/models_first_person_maze.c)
  67. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_custom_uniform.c)
  68. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_model_shader.c)
  69. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_postprocessing.c)
  70. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_raymarching.c)
  71. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_palette_switch.c)
  72. list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_basic_lighting.c)
  73. elseif(${PLATFORM} MATCHES "Web")
  74. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1")
  75. # Since WASM is used, ALLOW_MEMORY_GROWTH has no extra overheads
  76. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 --no-heap-copy")
  77. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --shell-file ${CMAKE_SOURCE_DIR}/src/shell.html")
  78. set(OUTPUT_EXT ".html")
  79. endif()
  80. include_directories(BEFORE SYSTEM others/external/include)
  81. if (NOT TARGET raylib)
  82. find_package(raylib 2.0 REQUIRED)
  83. endif()
  84. # Do each example
  85. foreach(example_source ${example_sources})
  86. # Create the basename for the example
  87. get_filename_component(example_name ${example_source} NAME)
  88. string(REPLACE ".c" "${OUTPUT_EXT}" example_name ${example_name})
  89. # Setup the example
  90. add_executable(${example_name} ${example_source})
  91. target_link_libraries(${example_name} raylib)
  92. string(REGEX MATCH ".*/.*/" resources_dir ${example_source})
  93. string(APPEND resources_dir "resources")
  94. if(${PLATFORM} MATCHES "Web" AND EXISTS ${resources_dir})
  95. # The local resources path needs to be mapped to /resources virtual path
  96. string(APPEND resources_dir "@resources")
  97. set_target_properties(${example_name} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}")
  98. endif()
  99. endforeach()
  100. if (${PLATFORM} MATCHES "Desktop")
  101. # rlgl_standalone can't be linked with raylib because of duplicate rlgl symbols
  102. foreach (example_source "others/rlgl_standalone.c")
  103. # Create the basename for the example
  104. get_filename_component(example_name ${example_source} NAME)
  105. string(REPLACE ".c" "${OUTPUT_EXT}" example_name ${example_name})
  106. add_executable(${example_name} ${example_source})
  107. add_dependencies(${example_name} raylib)
  108. target_link_libraries(${example_name} ${raylib_LDFLAGS})
  109. target_include_directories(${example_name} PRIVATE ${raylib_INCLUDE_DIRS})
  110. endforeach()
  111. endif()
  112. # Copy all of the resource files to the destination
  113. file(COPY ${example_resources} DESTINATION "resources/")