test-static-lib/CMakeLists.txt

54 lines
1.6 KiB
CMake
Raw Permalink Normal View History

2020-05-17 23:16:40 +02:00
cmake_minimum_required(VERSION 3.9)
# project definition
project(test_static_library LANGUAGES C VERSION 1.0.0 DESCRIPTION "Static C Library for testing of various cmake configurations")
set(CMAKE_C_STANDARD 99)
include(GNUInstallDirs)
enable_testing()
# define library
2020-05-18 13:22:03 +02:00
add_library(test_static_library STATIC src/test_static_library.c include/test_static_library.h)
2020-05-17 23:16:40 +02:00
# library properties and meta vars
set_target_properties(test_static_library PROPERTIES
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER include/test_static_library.h)
#target_include_directories(test_shared_library PRIVATE .)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)
# pkg-config props
2020-05-18 13:22:03 +02:00
configure_file(test_static_library.pc.in test_static_library.pc @ONLY)
2020-05-17 23:16:40 +02:00
# export native cmake package
2020-05-18 13:22:03 +02:00
install(TARGETS test_static_library EXPORT test_static_libraryConfig
2020-05-18 13:26:05 +02:00
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
2020-05-17 23:16:40 +02:00
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# export pkg-config package
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
# install exported packages
2020-05-18 13:22:03 +02:00
install(EXPORT test_static_libraryConfig DESTINATION share/${PROJECT_NAME}/cmake)
export(TARGETS test_static_library FILE test_static_libraryConfig.cmake)
2020-05-17 23:16:40 +02:00
message(STATUS "${CMAKE_C_FLAGS}")
# test executable
add_executable(test_library test.c)
2020-05-18 13:22:03 +02:00
target_link_libraries(test_library test_static_library)
2020-05-17 23:16:40 +02:00
# testing support with make test
2020-05-18 13:22:03 +02:00
add_test(test_static test_library)
2020-05-17 23:16:40 +02:00