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
2020-05-17 22:17:59 +02:00
project(test_shared_library LANGUAGES C VERSION 1.1.1 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
2020-05-17 22:17:59 +02:00
add_library(test_shared_library SHARED src/test_shared_library.c include/test_shared_library.h)
2020-05-17 21:52:14 +02:00
# library properties - dynamic
2020-05-16 23:32:17 +02:00
set_target_properties(test_shared_library PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
2020-05-17 22:17:59 +02:00
PUBLIC_HEADER include/test_shared_library.h)
2020-05-16 23:32:17 +02:00
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
2020-05-17 22:17:59 +02:00
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)
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)