cmake_minimum_required(VERSION 3.9) # project properties, version etc project(test_shared_library LANGUAGES C VERSION 1.1.1 DESCRIPTION "Shared C Library for testing of various cmake configurations") set(CMAKE_C_STANDARD 99) # include GNU Install dirs include(GNUInstallDirs) enable_testing() # define library add_library(test_shared_library SHARED src/test_shared_library.c include/test_shared_library.h) # library properties - dynamic set_target_properties(test_shared_library PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1 PUBLIC_HEADER include/test_shared_library.h) # pkg-config stuff configure_file(test_shared_library.pc.in test_shared_library.pc @ONLY) #target_include_directories(test_shared_library PRIVATE .) target_include_directories(${PROJECT_NAME} PUBLIC $ $ PRIVATE src) # export native cmake package install(TARGETS test_shared_library EXPORT test_shared_libraryConfig LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # export pkg-config package install(FILES ${CMAKE_BINARY_DIR}/test_shared_library.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) # install exported packages install(EXPORT test_shared_libraryConfig DESTINATION share/test_shared_library/cmake) export(TARGETS ${PROJECT_NAME} FILE test_shared_libraryConfig.cmake) # test executable add_executable(test_library test.c) target_link_libraries(test_library test_shared_library) # testing support with make test add_test(test_shared_lib_dynamic test_library)