🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

124 lines
5.4 KiB

  1. # This cmake build script is meant for verifying the various CMake configuration script.
  2. cmake_minimum_required(VERSION 3.12)
  3. project(sdl_test LANGUAGES C)
  4. include(GenerateExportHeader)
  5. if(ANDROID)
  6. macro(add_executable NAME)
  7. set(args ${ARGN})
  8. list(REMOVE_ITEM args WIN32)
  9. add_library(${NAME} SHARED ${args})
  10. unset(args)
  11. endmacro()
  12. endif()
  13. cmake_policy(SET CMP0074 NEW)
  14. # Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL2 outside of sysroot
  15. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
  16. include(FeatureSummary)
  17. option(TEST_SHARED "Test linking to shared SDL2 library" ON)
  18. add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library")
  19. option(TEST_STATIC "Test linking to static SDL2 library" ON)
  20. add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")
  21. if(TEST_SHARED)
  22. find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2)
  23. if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE))
  24. find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
  25. endif()
  26. add_executable(gui-shared WIN32 main_gui.c)
  27. if(TARGET SDL2::SDL2main)
  28. target_link_libraries(gui-shared PRIVATE SDL2::SDL2main)
  29. endif()
  30. target_link_libraries(gui-shared PRIVATE SDL2::SDL2)
  31. if(WIN32)
  32. add_custom_command(TARGET gui-shared POST_BUILD
  33. COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:gui-shared>"
  34. )
  35. endif()
  36. add_library(sharedlib-shared SHARED main_lib.c)
  37. target_link_libraries(sharedlib-shared PRIVATE SDL2::SDL2)
  38. generate_export_header(sharedlib-shared EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
  39. target_compile_definitions(sharedlib-shared PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared_export.h\"")
  40. set_target_properties(sharedlib-shared PROPERTIES C_VISIBILITY_PRESET "hidden")
  41. add_executable(gui-shared-vars WIN32 main_gui.c)
  42. target_link_libraries(gui-shared-vars PRIVATE ${SDL2_LIBRARIES})
  43. target_include_directories(gui-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS})
  44. add_executable(cli-shared main_cli.c)
  45. target_link_libraries(cli-shared PRIVATE SDL2::SDL2)
  46. if(WIN32)
  47. add_custom_command(TARGET cli-shared POST_BUILD
  48. COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:SDL2::SDL2>" "$<TARGET_FILE_DIR:cli-shared>"
  49. )
  50. endif()
  51. # SDL2_LIBRARIES does not support creating a cli SDL2 application
  52. # (it is possible that SDL2main is a stub, but we don't know for sure)
  53. if(NOT TARGET SDL2::SDL2main)
  54. add_executable(cli-shared-vars main_cli.c)
  55. target_link_libraries(cli-shared-vars PRIVATE ${SDL2_LIBRARIES})
  56. target_include_directories(cli-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS})
  57. endif()
  58. add_library(sharedlib-shared-vars SHARED main_lib.c)
  59. target_link_libraries(sharedlib-shared-vars PRIVATE ${SDL2_LIBRARIES})
  60. target_include_directories(sharedlib-shared-vars PRIVATE ${SDL2_INCLUDE_DIRS})
  61. generate_export_header(sharedlib-shared-vars EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
  62. target_compile_definitions(sharedlib-shared-vars PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-shared-vars_export.h\"")
  63. set_target_properties(sharedlib-shared-vars PROPERTIES C_VISIBILITY_PRESET "hidden")
  64. endif()
  65. if(TEST_STATIC)
  66. find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2-static)
  67. if(EMSCRIPTEN OR (WIN32 AND NOT WINDOWS_STORE))
  68. find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
  69. endif()
  70. add_executable(gui-static WIN32 main_gui.c)
  71. if(TARGET SDL2::SDL2main)
  72. target_link_libraries(gui-static PRIVATE SDL2::SDL2main)
  73. endif()
  74. target_link_libraries(gui-static PRIVATE SDL2::SDL2-static)
  75. option(SDL_STATIC_PIC "SDL static library has been built with PIC")
  76. if(SDL_STATIC_PIC OR WIN32)
  77. add_library(sharedlib-static SHARED main_lib.c)
  78. target_link_libraries(sharedlib-static PRIVATE SDL2::SDL2-static)
  79. generate_export_header(sharedlib-static EXPORT_MACRO_NAME MYLIBRARY_EXPORT)
  80. target_compile_definitions(sharedlib-static PRIVATE "EXPORT_HEADER=\"${CMAKE_CURRENT_BINARY_DIR}/sharedlib-static_export.h\"")
  81. set_target_properties(sharedlib-static PROPERTIES C_VISIBILITY_PRESET "hidden")
  82. endif()
  83. add_executable(gui-static-vars WIN32 main_gui.c)
  84. target_link_libraries(gui-static-vars PRIVATE ${SDL2MAIN_LIBRARY} ${SDL2_STATIC_LIBRARIES})
  85. target_include_directories(gui-static-vars PRIVATE ${SDL2_INCLUDE_DIRS})
  86. add_executable(cli-static main_cli.c)
  87. target_link_libraries(cli-static PRIVATE SDL2::SDL2-static)
  88. # SDL2_LIBRARIES does not support creating a cli SDL2 application (when SDL2::SDL2main is available)
  89. # (it is possible that SDL2main is a stub, but we don't know for sure)
  90. if(NOT TARGET SDL2::SDL2main)
  91. add_executable(cli-static-vars main_cli.c)
  92. target_link_libraries(cli-static-vars PRIVATE ${SDL2_STATIC_LIBRARIES})
  93. target_include_directories(cli-static-vars PRIVATE ${SDL2_INCLUDE_DIRS})
  94. endif()
  95. endif()
  96. message(STATUS "SDL2_PREFIX: ${SDL2_PREFIX}")
  97. message(STATUS "SDL2_INCLUDE_DIR: ${SDL2_INCLUDE_DIR}")
  98. message(STATUS "SDL2_INCLUDE_DIRS: ${SDL2_INCLUDE_DIRS}")
  99. message(STATUS "SDL2_LIBRARIES: ${SDL2_LIBRARIES}")
  100. message(STATUS "SDL2_STATIC_LIBRARIES: ${SDL2_STATIC_LIBRARIES}")
  101. message(STATUS "SDL2MAIN_LIBRARY: ${SDL2MAIN_LIBRARY}")
  102. message(STATUS "SDL2TEST_LIBRARY: ${SDL2TEST_LIBRARY}")
  103. feature_summary(WHAT ALL)