🛠️🐜 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.

105 lines
3.3 KiB

  1. # this cmake file is for compile tests.
  2. # Not usable for your cmake app.
  3. cmake_minimum_required(VERSION 3.5)
  4. set(BUILD_TARGET "tinyexr")
  5. set(SAMPLE_TARGET "test_tinyexr")
  6. project(${BUILD_TARGET} CXX)
  7. # options
  8. option(TINYEXR_BUILD_SAMPLE "Build a sample" ON)
  9. option(TINYEXR_USE_MINIZ "Use miniz" ON)
  10. # cmake modules
  11. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
  12. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/sanitizers)
  13. find_package(Sanitizers) # Address sanitizer (-DSANITIZE_ADDRESS=ON)
  14. # Require strict C++11 mode(e.g. `-std=c++11`)
  15. set(CMAKE_CXX_STANDARD 11)
  16. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  17. set(CMAKE_CXX_EXTENSIONS OFF)
  18. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  19. set(TINYEXR_SOURCES
  20. ${PROJECT_SOURCE_DIR}/tinyexr.cc
  21. )
  22. if(TINYEXR_USE_MINIZ)
  23. enable_language(C)
  24. add_library(miniz STATIC deps/miniz/miniz.c)
  25. target_include_directories(miniz PUBLIC deps/miniz)
  26. set_target_properties(miniz PROPERTIES FOLDER "deps")
  27. list(APPEND TINYEXR_EXT_LIBRARIES miniz)
  28. endif()
  29. add_library(${BUILD_TARGET} ${TINYEXR_SOURCES} ${TINYEXR_DEP_SOURCES})
  30. add_sanitizers(${BUILD_TARGET})
  31. target_compile_definitions(${BUILD_TARGET} PUBLIC TINYEXR_USE_MINIZ=0)
  32. target_compile_definitions(${BUILD_TARGET} PUBLIC TINYEXR_USE_STB_ZLIB=1)
  33. target_include_directories(${BUILD_TARGET} PRIVATE ${PROJECT_SOURCE_DIR})
  34. target_link_libraries(${BUILD_TARGET} ${TINYEXR_EXT_LIBRARIES} ${CMAKE_DL_LIBS})
  35. # Install library
  36. install(TARGETS ${PROJECT_NAME}
  37. EXPORT ${PROJECT_NAME}-targets
  38. ARCHIVE DESTINATION lib
  39. LIBRARY DESTINATION lib
  40. RUNTIME DESTINATION bin)
  41. # Install headers
  42. install(
  43. FILES
  44. ${PROJECT_SOURCE_DIR}/tinyexr.h
  45. DESTINATION include)
  46. # Install CMake config file
  47. install(EXPORT ${PROJECT_NAME}-targets
  48. FILE ${PROJECT_NAME}-targets.cmake
  49. DESTINATION lib/cmake/${PROJECT_NAME})
  50. include(CMakePackageConfigHelpers)
  51. configure_package_config_file(
  52. ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake.in
  53. ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
  54. INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})
  55. install(
  56. FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
  57. DESTINATION lib/cmake/${PROJECT_NAME})
  58. # Increase warning level for clang.
  59. IF (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  60. set_source_files_properties(${TINYEXR_SOURCES} PROPERTIES COMPILE_FLAGS "-Weverything -Werror -Wno-padded -Wno-c++98-compat-pedantic -Wno-documentation -Wno-unused-member-function")
  61. ENDIF ()
  62. if (TINYEXR_BUILD_SAMPLE)
  63. set(TINYEXR_SAMPLE_SOURCES
  64. ${PROJECT_SOURCE_DIR}/test_tinyexr.cc
  65. )
  66. add_executable(${SAMPLE_TARGET} ${TINYEXR_SAMPLE_SOURCES})
  67. target_link_libraries(${SAMPLE_TARGET} ${TINYEXR_EXT_LIBRARIES})
  68. add_sanitizers(${SAMPLE_TARGET})
  69. if (WIN32)
  70. target_compile_definitions(${SAMPLE_TARGET} PUBLIC UNICODE)
  71. target_compile_definitions(${SAMPLE_TARGET} PUBLIC _UNICODE)
  72. # Set ${SAMPLE_TARGET} as a startup project for VS IDE
  73. set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${SAMPLE_TARGET})
  74. # For easier debugging in VS IDE(cmake 3.8.0 or later required) Set working
  75. # directory to ${BUILD_TARGET} git repo root.
  76. if(CMAKE_VERSION VERSION_GREATER 3.8.0)
  77. set_target_properties(${SAMPLE_TARGET}
  78. PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY
  79. "${CMAKE_CURRENT_SOURCE_DIR}")
  80. endif()
  81. endif(WIN32)
  82. endif (TINYEXR_BUILD_SAMPLE)