test-static-lib/CMakeLists.txt

53 lines
1.6 KiB
CMake
Raw 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
add_library(${PROJECT_NAME} STATIC src/test_static_library.c include/test_static_library.h)
# 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
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
# export native cmake package
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
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
install(EXPORT ${PROJECT_NAME}Config DESTINATION share/${PROJECT_NAME}/cmake)
export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}Config.cmake)
message(STATUS "${CMAKE_C_FLAGS}")
# test executable
add_executable(test_library test.c)
target_link_libraries(test_library ${PROJECT_NAME})
# testing support with make test
add_test(test_shared_lib_dynamic test_library)