CMakeLists.txt
1 # SPDX-FileCopyrightText: 2023-2024 Le'Core collective 2 # 3 # SPDX-License-Identifier: LGPL-3.0-or-later 4 5 set(core_public_header_base ../include) 6 set(core_public_header_subdir lecore) 7 set(core_public_header_dir ${core_public_header_base}/${core_public_header_subdir}) 8 set(core_public_headers 9 macros.h 10 types.h 11 core.h 12 environment.h 13 plugin.h) 14 list(TRANSFORM core_public_headers 15 PREPEND ${core_public_header_dir}/) 16 17 set(core_generated_public_header_base ${CMAKE_CURRENT_BINARY_DIR}/../include) 18 set(core_generated_public_header_dir ${core_generated_public_header_base}/${core_public_header_subdir}) 19 set(core_generated_public_headers 20 config.h 21 export.h) 22 list(TRANSFORM core_generated_public_headers 23 PREPEND ${core_generated_public_header_dir}/) 24 25 set(core_source 26 environment.c 27 plugin.c 28 ) 29 30 configure_file( 31 ${core_public_header_dir}/config.h.in 32 ${core_generated_public_header_dir}/config.h 33 ) 34 35 include(GenerateExportHeader) 36 set(core_export_custom_content 37 [=====[ 38 39 // Generated by cmake using GenerateExportHeader 40 ]=====]) 41 42 # The static variant of the library 43 add_library(lecore_s STATIC) 44 target_compile_definitions(lecore_s PRIVATE LE_CORE_STATIC_DEFINE) 45 46 # The shared variant of the library 47 add_library(lecore SHARED) 48 set_target_properties(lecore PROPERTIES SOVERSION 0) 49 generate_export_header(lecore 50 BASE_NAME LE_CORE 51 EXPORT_FILE_NAME ${core_generated_public_header_dir}/export.h 52 CUSTOM_CONTENT_FROM_VARIABLE core_export_custom_content) 53 54 # Common interface, mostly done this way to avoid double installation of headers 55 add_library(lecore_interface INTERFACE) 56 target_include_directories(lecore_interface 57 INTERFACE 58 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${core_public_header_base}> 59 $<BUILD_INTERFACE:${core_generated_public_header_base}> 60 $<INSTALL_INTERFACE:include>) 61 target_sources(lecore_interface 62 INTERFACE 63 FILE_SET public_headers 64 TYPE HEADERS 65 BASE_DIRS ${core_public_header_base} 66 FILES ${core_public_headers}) 67 target_sources(lecore_interface 68 INTERFACE 69 FILE_SET generated_public_headers 70 TYPE HEADERS 71 BASE_DIRS ${core_generated_public_header_base} 72 FILES ${core_generated_public_headers}) 73 74 # Specify everything that's common for both the static and the shared libraries 75 foreach(core_lib lecore_s lecore) 76 target_sources(${core_lib} 77 PRIVATE 78 ${core_source} 79 $<TARGET_OBJECTS:hashmap>) 80 set_target_properties(${core_lib} 81 PROPERTIES 82 VISIBILITY_INLINES_HIDDEN 1 83 C_VISIBILITY_PRESET hidden 84 LINKER_LANGUAGE C) 85 target_include_directories(${core_lib} 86 PUBLIC 87 $<TARGET_PROPERTY:lecore_interface,INTERFACE_INCLUDE_DIRECTORIES> 88 $<TARGET_PROPERTY:leutils,INTERFACE_INCLUDE_DIRECTORIES> 89 PRIVATE 90 $<TARGET_PROPERTY:hashmap,INTERFACE_INCLUDE_DIRECTORIES> 91 ) 92 target_link_libraries(${core_lib} PUBLIC leutils ${CMAKE_DL_LIBS}) 93 endforeach() 94 95 install(TARGETS lecore_interface lecore_s lecore 96 EXPORT LeCoreConfig 97 RUNTIME 98 DESTINATION ${CMAKE_INSTALL_BINDIR} 99 COMPONENT Libraries 100 LIBRARY 101 DESTINATION ${CMAKE_INSTALL_LIBDIR} 102 COMPONENT Libraries 103 NAMELINK_COMPONENT Development 104 ARCHIVE 105 DESTINATION ${CMAKE_INSTALL_LIBDIR} 106 COMPONENT Development 107 FILE_SET public_headers 108 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 109 COMPONENT Development 110 FILE_SET generated_public_headers 111 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 112 COMPONENT Development) 113 114 # Unit test of LeCore_env_t 115 add_executable(unit_test_environment 116 environment.c 117 $<TARGET_OBJECTS:hashmap>) 118 target_compile_definitions(unit_test_environment 119 PRIVATE 120 LE_CORE_STATIC_DEFINE 121 TEST_ENVIRONMENT) 122 target_include_directories(unit_test_environment 123 PRIVATE 124 $<TARGET_PROPERTY:hashmap,INTERFACE_INCLUDE_DIRECTORIES>) 125 target_link_libraries(unit_test_environment PRIVATE lecore_s) 126 add_test(NAME unit_test_environment COMMAND unit_test_environment) 127 128 # Unit test of plugins 129 add_executable(unit_test_plugin plugin.c) 130 target_compile_definitions(unit_test_plugin 131 PRIVATE 132 LE_CORE_STATIC_DEFINE 133 TEST_PLUGIN) 134 target_link_libraries(unit_test_plugin PRIVATE lecore_s) 135 add_test(NAME unit_test_plugin COMMAND unit_test_plugin) 136 137 # Unit test of implementations 138 add_executable(unit_test_implementation implementation.c) 139 target_compile_definitions(unit_test_implementation 140 PRIVATE 141 LE_CORE_STATIC_DEFINE 142 TEST_IMPLEMENTATION TEST_IMPLEMENTATION_DEBUG) 143 target_include_directories(unit_test_implementation 144 PRIVATE 145 $<TARGET_PROPERTY:hashmap,INTERFACE_INCLUDE_DIRECTORIES>) 146 target_link_libraries(unit_test_implementation PRIVATE lecore_s) 147 add_test(NAME unit_test_implementation COMMAND unit_test_implementation)