|
| 1 | +cmake_minimum_required(VERSION 3.14) |
| 2 | + |
| 3 | +project(thermo |
| 4 | + VERSION 1.1.0 |
| 5 | + DESCRIPTION "Type-safe temperature handling library modeled after std::chrono" |
| 6 | + HOMEPAGE_URL "https://github.com/cleishm/thermo-cpp" |
| 7 | + LANGUAGES CXX |
| 8 | +) |
| 9 | + |
| 10 | +# ESP-IDF component support |
| 11 | +if(ESP_PLATFORM) |
| 12 | + idf_component_register(INCLUDE_DIRS "include") |
| 13 | + return() |
| 14 | +endif() |
| 15 | + |
| 16 | +option(THERMO_BUILD_TESTS "Build tests" ${thermo_IS_TOP_LEVEL}) |
| 17 | + |
| 18 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 19 | + |
| 20 | +# Main library target (header-only) |
| 21 | +add_library(thermo INTERFACE) |
| 22 | +add_library(thermo::thermo ALIAS thermo) |
| 23 | + |
| 24 | +target_include_directories(thermo INTERFACE |
| 25 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 26 | + $<INSTALL_INTERFACE:include> |
| 27 | +) |
| 28 | + |
| 29 | +target_compile_features(thermo INTERFACE cxx_std_23) |
| 30 | + |
| 31 | +# Tests |
| 32 | +if(THERMO_BUILD_TESTS) |
| 33 | + enable_testing() |
| 34 | + add_subdirectory(tests) |
| 35 | +endif() |
| 36 | + |
| 37 | +# Documentation |
| 38 | +option(THERMO_BUILD_DOCS "Build documentation" OFF) |
| 39 | + |
| 40 | +if(THERMO_BUILD_DOCS) |
| 41 | + find_package(Doxygen) |
| 42 | + if(DOXYGEN_FOUND) |
| 43 | + set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs) |
| 44 | + add_custom_target(docs |
| 45 | + COMMAND ${CMAKE_COMMAND} -E make_directory ${DOXYGEN_OUTPUT_DIRECTORY} |
| 46 | + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile |
| 47 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs |
| 48 | + COMMENT "Generating API documentation with Doxygen" |
| 49 | + VERBATIM |
| 50 | + ) |
| 51 | + message(STATUS "Doxygen found: documentation can be built with 'make docs'") |
| 52 | + else() |
| 53 | + message(WARNING "Doxygen not found: documentation cannot be built") |
| 54 | + endif() |
| 55 | +endif() |
| 56 | + |
| 57 | +# Installation |
| 58 | +include(GNUInstallDirs) |
| 59 | +include(CMakePackageConfigHelpers) |
| 60 | + |
| 61 | +install(TARGETS thermo |
| 62 | + EXPORT thermoTargets |
| 63 | + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 64 | +) |
| 65 | + |
| 66 | +install(DIRECTORY include/ |
| 67 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 68 | +) |
| 69 | + |
| 70 | +install(EXPORT thermoTargets |
| 71 | + FILE thermoTargets.cmake |
| 72 | + NAMESPACE thermo:: |
| 73 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/thermo |
| 74 | +) |
| 75 | + |
| 76 | +configure_package_config_file( |
| 77 | + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/thermoConfig.cmake.in |
| 78 | + ${CMAKE_CURRENT_BINARY_DIR}/thermoConfig.cmake |
| 79 | + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/thermo |
| 80 | +) |
| 81 | + |
| 82 | +write_basic_package_version_file( |
| 83 | + ${CMAKE_CURRENT_BINARY_DIR}/thermoConfigVersion.cmake |
| 84 | + VERSION ${PROJECT_VERSION} |
| 85 | + COMPATIBILITY SameMajorVersion |
| 86 | +) |
| 87 | + |
| 88 | +install(FILES |
| 89 | + ${CMAKE_CURRENT_BINARY_DIR}/thermoConfig.cmake |
| 90 | + ${CMAKE_CURRENT_BINARY_DIR}/thermoConfigVersion.cmake |
| 91 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/thermo |
| 92 | +) |
0 commit comments