cmake_minimum_required(VERSION 3.16) project(tstd C) set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Sources (headers are installed, not compiled) set(TSTD_SOURCES library.c string.c ) # Shared library: libtstd.so add_library(tstd SHARED ${TSTD_SOURCES}) target_include_directories(tstd PUBLIC $ $ ) set_target_properties(tstd PROPERTIES OUTPUT_NAME tstd VERSION 1.1.0 SOVERSION 1 POSITION_INDEPENDENT_CODE ON ) # Static library: libtstd.a (named tstd_static target, outputs libtstd.a) add_library(tstd_static STATIC ${TSTD_SOURCES}) target_include_directories(tstd_static PUBLIC $ $ ) set_target_properties(tstd_static PROPERTIES OUTPUT_NAME tstd POSITION_INDEPENDENT_CODE ON ) # Tests/executables can choose which one to link add_executable(test_tstd_string test/test_string.c) add_executable(test_tstd_list test/test_list.c) # Link dynamically by default: target_link_libraries(test_tstd_string PRIVATE tstd) target_link_libraries(test_tstd_list PRIVATE tstd) # If you want static instead, swap to tstd_static. enable_testing() add_test(NAME tstd_tests_string COMMAND test_tstd_string) add_test(NAME tstd_tests_list COMMAND test_tstd_list) # Install libs + headers install(TARGETS tstd tstd_static EXPORT tstdTargets LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include ) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include )