test-shared-lib/CMakeLists.txt

45 lines
1.6 KiB
CMake
Raw Normal View History

2020-05-16 23:32:17 +02:00
cmake_minimum_required(VERSION 3.9)
2020-05-17 21:52:14 +02:00
# project properties, version etc
project(test_shared_library LANGUAGES C VERSION 1.0.3 DESCRIPTION "Shared C Library for testing of various cmake configurations")
2020-05-16 23:32:17 +02:00
set(CMAKE_C_STANDARD 99)
2020-05-17 21:52:14 +02:00
# include GNU Install dirs
include(GNUInstallDirs)
2020-05-17 10:11:58 +02:00
enable_testing()
2020-05-16 23:32:17 +02:00
2020-05-17 21:52:14 +02:00
# define library
add_library(test_shared_library SHARED test_shared_library.c test_shared_library.h)
# library properties - dynamic
2020-05-16 23:32:17 +02:00
set_target_properties(test_shared_library PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER test_shared_library.h)
2020-05-17 21:52:14 +02:00
# pkg-config stuff
2020-05-16 23:32:17 +02:00
configure_file(test_shared_library.pc.in test_shared_library.pc @ONLY)
2020-05-17 21:52:14 +02:00
#target_include_directories(test_shared_library PRIVATE .)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:>
PRIVATE .)
2020-05-16 23:32:17 +02:00
2020-05-17 21:52:14 +02:00
# export native cmake package
install(TARGETS test_shared_library EXPORT test_shared_libraryConfig
2020-05-16 23:32:17 +02:00
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
2020-05-17 21:52:14 +02:00
# export pkg-config package
2020-05-16 23:32:17 +02:00
install(FILES ${CMAKE_BINARY_DIR}/test_shared_library.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
2020-05-17 21:53:37 +02:00
# install exported packages
2020-05-17 21:52:14 +02:00
install(EXPORT test_shared_libraryConfig DESTINATION share/test_shared_library/cmake)
2020-05-17 21:53:37 +02:00
export(TARGETS ${PROJECT_NAME} FILE test_shared_libraryConfig.cmake)
2020-05-17 10:05:20 +02:00
2020-05-17 21:53:37 +02:00
# test executable
2020-05-17 10:11:58 +02:00
add_executable(test_library test.c)
target_link_libraries(test_library test_shared_library)
2020-05-17 21:53:37 +02:00
# testing support with make test
2020-05-17 10:11:58 +02:00
add_test(test_shared_lib_dynamic test_library)