CMakeLists.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. cmake_minimum_required(VERSION 3.10)
  2. project(heatshrink LANGUAGES C VERSION 0.4.1)
  3. set(CMAKE_C_STANDARD 99)
  4. set(CMAKE_C_STANDARD_REQUIRED ON)
  5. set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
  6. add_library(${PROJECT_NAME} heatshrink_decoder.c heatshrink_encoder.c)
  7. add_library(${PROJECT_NAME}_dynalloc heatshrink_decoder.c heatshrink_encoder.c)
  8. find_library(MATH_LIBRARY m) # Business as usual
  9. if(MATH_LIBRARY)
  10. target_link_libraries(${PROJECT_NAME} PUBLIC ${MATH_LIBRARY})
  11. endif()
  12. target_include_directories(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
  13. target_include_directories(${PROJECT_NAME}_dynalloc PUBLIC $<INSTALL_INTERFACE:include>)
  14. target_compile_definitions(${PROJECT_NAME} PUBLIC HEATSHRINK_DYNAMIC_ALLOC=0)
  15. target_compile_definitions(${PROJECT_NAME}_dynalloc PUBLIC HEATSHRINK_DYNAMIC_ALLOC=1)
  16. if (UNIX)
  17. add_executable(${PROJECT_NAME}_cmd heatshrink.c)
  18. target_link_libraries(${PROJECT_NAME}_cmd ${PROJECT_NAME}_dynalloc)
  19. set_target_properties(${PROJECT_NAME}_cmd PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
  20. endif ()
  21. foreach (tgt ${PROJECT_NAME} ${PROJECT_NAME}_dynalloc)
  22. set_target_properties(${tgt}
  23. PROPERTIES
  24. VERSION ${PROJECT_VERSION}
  25. SOVERSION ${PROJECT_VERSION})
  26. endforeach()
  27. # Installation and export:
  28. include(CMakePackageConfigHelpers)
  29. write_basic_package_version_file(
  30. "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
  31. VERSION ${PROJECT_VERSION}
  32. COMPATIBILITY AnyNewerVersion
  33. )
  34. set(_exported_targets ${PROJECT_NAME} ${PROJECT_NAME}_dynalloc)
  35. if (UNIX)
  36. list(APPEND _exported_targets ${PROJECT_NAME}_cmd)
  37. endif ()
  38. install(TARGETS ${_exported_targets}
  39. EXPORT ${PROJECT_NAME}Targets
  40. )
  41. export(EXPORT ${PROJECT_NAME}Targets
  42. FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
  43. NAMESPACE ${PROJECT_NAME}::
  44. )
  45. include(GNUInstallDirs)
  46. set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  47. configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
  48. "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  49. INSTALL_DESTINATION ${ConfigPackageLocation}
  50. )
  51. install(
  52. FILES
  53. heatshrink_common.h
  54. heatshrink_config.h
  55. heatshrink_encoder.h
  56. heatshrink_decoder.h
  57. DESTINATION
  58. include/${PROJECT_NAME}
  59. )
  60. install(EXPORT ${PROJECT_NAME}Targets
  61. FILE
  62. ${PROJECT_NAME}Targets.cmake
  63. NAMESPACE
  64. ${PROJECT_NAME}::
  65. DESTINATION
  66. ${ConfigPackageLocation}
  67. )
  68. install(
  69. FILES
  70. "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  71. "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
  72. DESTINATION
  73. ${ConfigPackageLocation}
  74. )