summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2019-11-19 15:55:15 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-11-19 15:55:15 +0100
commite4c51ce9a4792d7d301d49e4e962036bfaa7f75e (patch)
tree64343fc5978063e7d90548fd74316e32d0a21f75
parent28ce16b29911e5adc60140b572dee177adc7a178 (diff)
downloadcmocka-e4c51ce9a4792d7d301d49e4e962036bfaa7f75e.tar.gz
cmocka-e4c51ce9a4792d7d301d49e4e962036bfaa7f75e.tar.xz
cmocka-e4c51ce9a4792d7d301d49e4e962036bfaa7f75e.zip
cmake: Export cmake config for cmocka
For backwards compatibility use: find_package(cmocka REQUIRED) if (NOT TARGET cmocka) add_library(cmocka SHARED IMPORTED) set_target_properties(cmocka PROPERTIES IMPORTED_LOCATION "${CMOCKA_LIBRARIES}" INTERFACE_INCLUDE_DIRECTORIES "${CMOCKA_INCLUDE_DIR}") endif() target_link_libraries(mylib cmocka)
-rw-r--r--CMakeLists.txt33
-rw-r--r--src/CMakeLists.txt23
2 files changed, 14 insertions, 42 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7e3ede3..ababa8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,40 +75,13 @@ install(
pkgconfig
)
-# cmake config files
-if (WIN32)
- set(CMOCKA_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})
-else()
- set(CMOCKA_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
-endif()
-
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmocka-build-tree-settings.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/cmocka-build-tree-settings.cmake
- @ONLY
-)
-
-set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE INTERNAL "")
-set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE INTERNAL "")
-configure_package_config_file(${PROJECT_NAME}-config.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
- PATH_VARS
- INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
- INSTALL_DESTINATION
- ${CMAKE_INSTALL_FULL_LIBDIR}/cmake/${PROJECT_NAME})
-
write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake
COMPATIBILITY
AnyNewerVersion)
-install(
- FILES
- ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
- ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
- DESTINATION
- ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
- COMPONENT
- devel
-)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
+ COMPONENT devel)
# Add 'make dist' target which makes sure to invoke cmake before
add_custom_target(dist
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 01b6838..2048a64 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -26,8 +26,8 @@ target_include_directories(cmocka
${CMOCKA_PLATFORM_INCLUDE}
${cmocka_BINARY_DIR}
PUBLIC
- ${cmocka-header_SOURCE_DIR})
-
+ $<BUILD_INTERFACE:${cmocka-header_SOURCE_DIR}>
+ $<INSTALL_INTERFACE:include>)
target_compile_options(cmocka
PRIVATE
@@ -67,16 +67,15 @@ set_property(TARGET
add_library(cmocka::cmocka ALIAS cmocka)
-install(TARGETS
- cmocka
- ARCHIVE DESTINATION
- ${CMAKE_INSTALL_LIBDIR}
- LIBRARY DESTINATION
- ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION
- ${CMAKE_INSTALL_BINDIR}
- COMPONENT
- ${PROJECT_NAME})
+install(TARGETS cmocka
+ EXPORT cmocka-config
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ COMPONENT ${PROJECT_NAME})
+
+install(EXPORT cmocka-config
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cmocka)
if (UNIT_TESTING)
# Internal library