|
| 1 | +cmake_minimum_required(VERSION 3.21) |
| 2 | + |
| 3 | +project(microtimer VERSION 1.0.0 LANGUAGES C) |
| 4 | + |
| 5 | +include(CMakePackageConfigHelpers) |
| 6 | +include(GNUInstallDirs) |
| 7 | + |
| 8 | +set(MICROTIMER_MAX_TIMERS "8" CACHE STRING "Resolved timer capacity for this build") |
| 9 | +option(MICROTIMER_BUILD_TESTS "Build microtimer tests" ${PROJECT_IS_TOP_LEVEL}) |
| 10 | + |
| 11 | +configure_file( |
| 12 | + "${CMAKE_CURRENT_SOURCE_DIR}/include/mtimer_config.h.in" |
| 13 | + "${CMAKE_CURRENT_BINARY_DIR}/include/mtimer_config.h" |
| 14 | + @ONLY) |
| 15 | + |
| 16 | +add_library(microtimer src/mtimer.c) |
| 17 | +add_library(microtimer::microtimer ALIAS microtimer) |
| 18 | + |
| 19 | +target_compile_features(microtimer PUBLIC c_std_99) |
| 20 | +target_include_directories(microtimer |
| 21 | + PUBLIC |
| 22 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> |
| 23 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 24 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| 25 | + |
| 26 | +set_target_properties(microtimer PROPERTIES |
| 27 | + EXPORT_NAME microtimer |
| 28 | + VERSION ${PROJECT_VERSION} |
| 29 | + SOVERSION ${PROJECT_VERSION_MAJOR}) |
| 30 | + |
| 31 | +install(TARGETS microtimer |
| 32 | + EXPORT microtimerTargets |
| 33 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 34 | + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 35 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
| 36 | + |
| 37 | +install(FILES |
| 38 | + "${CMAKE_CURRENT_SOURCE_DIR}/include/mtimer.h" |
| 39 | + "${CMAKE_CURRENT_BINARY_DIR}/include/mtimer_config.h" |
| 40 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") |
| 41 | + |
| 42 | +install(EXPORT microtimerTargets |
| 43 | + FILE microtimerTargets.cmake |
| 44 | + NAMESPACE microtimer:: |
| 45 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/microtimer") |
| 46 | + |
| 47 | +write_basic_package_version_file( |
| 48 | + "${CMAKE_CURRENT_BINARY_DIR}/microtimerConfigVersion.cmake" |
| 49 | + VERSION ${PROJECT_VERSION} |
| 50 | + COMPATIBILITY SameMajorVersion) |
| 51 | + |
| 52 | +configure_package_config_file( |
| 53 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/microtimerConfig.cmake.in" |
| 54 | + "${CMAKE_CURRENT_BINARY_DIR}/microtimerConfig.cmake" |
| 55 | + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/microtimer") |
| 56 | + |
| 57 | +install(FILES |
| 58 | + "${CMAKE_CURRENT_BINARY_DIR}/microtimerConfig.cmake" |
| 59 | + "${CMAKE_CURRENT_BINARY_DIR}/microtimerConfigVersion.cmake" |
| 60 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/microtimer") |
| 61 | + |
| 62 | +if(MICROTIMER_BUILD_TESTS) |
| 63 | + enable_testing() |
| 64 | + add_subdirectory(tests) |
| 65 | +endif() |
0 commit comments