Update cmake exports

This commit is contained in:
Václav Valíček 2020-05-17 21:52:14 +02:00
parent 9227232eef
commit 986f9e6c3e

View File

@ -1,26 +1,39 @@
cmake_minimum_required(VERSION 3.9) cmake_minimum_required(VERSION 3.9)
project(test_shared_library LANGUAGES C VERSION 1.0.2 DESCRIPTION "Shared C Library for testing of various cmake configurations") # project properties, version etc
include(GNUInstallDirs) project(test_shared_library LANGUAGES C VERSION 1.0.3 DESCRIPTION "Shared C Library for testing of various cmake configurations")
add_library(test_shared_library SHARED test_shared_library.c test_shared_library.h)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
# include GNU Install dirs
include(GNUInstallDirs)
enable_testing() enable_testing()
# define library
add_library(test_shared_library SHARED test_shared_library.c test_shared_library.h)
# library properties - dynamic
set_target_properties(test_shared_library PROPERTIES set_target_properties(test_shared_library PROPERTIES
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION 1 SOVERSION 1
PUBLIC_HEADER test_shared_library.h) PUBLIC_HEADER test_shared_library.h)
# pkg-config stuff
configure_file(test_shared_library.pc.in test_shared_library.pc @ONLY) configure_file(test_shared_library.pc.in test_shared_library.pc @ONLY)
target_include_directories(test_shared_library PRIVATE .) #target_include_directories(test_shared_library PRIVATE .)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:>
PRIVATE .)
install(TARGETS test_shared_library EXPORT test_shared_library_export # export native cmake package
install(TARGETS test_shared_library EXPORT test_shared_libraryConfig
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# export pkg-config package
install(FILES ${CMAKE_BINARY_DIR}/test_shared_library.pc install(FILES ${CMAKE_BINARY_DIR}/test_shared_library.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
install(EXPORT test_shared_library_export DESTINATION share/test_shared_library/cmake) install(EXPORT test_shared_libraryConfig DESTINATION share/test_shared_library/cmake)
add_executable(test_library test.c) add_executable(test_library test.c)