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