diff options
author | Alexander Dahl <ada@thorsis.com> | 2023-03-17 10:06:12 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2024-02-02 11:27:10 +0100 |
commit | ea6ab8bc2696800549387aa9258354950bc148aa (patch) | |
tree | 6d9b4d2bed6b598100cd97a464b83519c4a56515 | |
parent | 53de473cddf20505f24f00d15b245591a0d0e6ad (diff) | |
download | cmocka-ea6ab8bc2696800549387aa9258354950bc148aa.zip cmocka-ea6ab8bc2696800549387aa9258354950bc148aa.tar.gz cmocka-ea6ab8bc2696800549387aa9258354950bc148aa.tar.bz2 |
cmake: Set CMOCKA_LIBRARIES in package config for backwards compatibility
Projects using cmocka could have done this successfully from version 1.0 to
1.1.5 to build against cmocka:
```
find_package(cmocka 1.0 REQUIRED CONFIG)
```
and later
```
target_link_libraries(myapp
${CMOCKA_LIBRARIES}
)
```
Modern apps should just "link" against 'cmocka::cmocka' instead like it's done in
examples already. To not break old builds (as it is the case with cmocka
release 1.1.7) we can put that modern target string into the variable
CMOCKA_LIBRARIES and thus trick old projects to just use that, keeping
compatibility until those projects explicitly use the modern version.
Link: https://cmake.org/cmake/help/latest/command/install.html#install-export
Link: https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#package-configuration-file
Link: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#module:CMakePackageConfigHelpers
Fixes: #87
Signed-off-by: Alexander Dahl <ada@thorsis.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit de67675842e549008f3e1aeb03ae7995afa3dd26)
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | cmocka-config.cmake.in | 10 | ||||
-rw-r--r-- | src/CMakeLists.txt | 4 |
3 files changed, 21 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7664bcc..6e923db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,11 +75,19 @@ install( pkgconfig ) +configure_package_config_file(cmocka-config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/cmocka-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cmocka" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake COMPATIBILITY AnyNewerVersion) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmocka-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} COMPONENT devel) diff --git a/cmocka-config.cmake.in b/cmocka-config.cmake.in new file mode 100644 index 0000000..d39bcb2 --- /dev/null +++ b/cmocka-config.cmake.in @@ -0,0 +1,10 @@ +@PACKAGE_INIT@ + +get_filename_component(cmocka_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +if(NOT TARGET cmocka::cmocka) + include("${cmocka_CMAKE_DIR}/cmocka-targets.cmake") +endif() + +# for backwards compatibility +set(CMOCKA_LIBRARY cmocka::cmocka) +set(CMOCKA_LIBRARIES cmocka::cmocka) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 155c347..c92b9ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,13 +68,13 @@ set_property(TARGET add_library(cmocka::cmocka ALIAS cmocka) install(TARGETS cmocka - EXPORT cmocka-config + EXPORT cmocka-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${PROJECT_NAME}) -install(EXPORT cmocka-config +install(EXPORT cmocka-targets NAMESPACE cmocka:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka) |