CMakeLists.txt
1 # SPDX-FileCopyrightText: 2023-2024 Le'Sec Core collective 2 # 3 # SPDX-License-Identifier: LGPL-3.0-or-later 4 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # See the NOTICE file distributed with this work for additional 8 # information regarding copyright ownership. 9 # You may obtain a copy of the License at 10 # 11 # http://www.apache.org/licenses/LICENSE-2.0 12 # 13 # Unless required by applicable law or agreed to in writing, software 14 # distributed under the License is distributed on an "AS IS" BASIS, 15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 # See the License for the specific language governing permissions and 17 # limitations under the License. 18 19 set(core_public_header_base ../../include) 20 set(core_public_header_subdir lscore) 21 set(core_public_header_dir ${core_public_header_base}/${core_public_header_subdir}) 22 set(core_public_headers 23 macros.h 24 types.h 25 data_set.h 26 environment.h 27 object.h 28 operation.h 29 registration.h 30 param.h 31 index.h) 32 list(TRANSFORM core_public_headers 33 PREPEND ${core_public_header_dir}/) 34 35 set(core_generated_public_header_base ${CMAKE_CURRENT_BINARY_DIR}/../../include) 36 set(core_generated_public_header_dir ${core_generated_public_header_base}/${core_public_header_subdir}) 37 set(core_generated_public_headers 38 info.h 39 export.h 40 plugin.h) 41 list(TRANSFORM core_generated_public_headers 42 PREPEND ${core_generated_public_header_dir}/) 43 44 set(core_source 45 environment.c 46 plugin.c 47 registration.c 48 index.c 49 info.c 50 ) 51 52 configure_file( 53 ${core_public_header_dir}/plugin.h.in 54 ${core_generated_public_header_dir}/plugin.h 55 ) 56 configure_file( 57 ${core_public_header_dir}/info.h.in 58 ${core_generated_public_header_dir}/info.h 59 ) 60 61 include(GenerateExportHeader) 62 set(core_export_custom_content 63 [=====[ 64 65 // Generated by cmake using GenerateExportHeader 66 ]=====]) 67 68 # The static variant of the library 69 add_library(lscore_s STATIC) 70 target_compile_definitions(lscore_s PRIVATE LSC_STATIC_DEFINE) 71 72 # The shared variant of the library 73 add_library(lscore SHARED) 74 set_target_properties(lscore PROPERTIES SOVERSION 0) 75 generate_export_header(lscore 76 BASE_NAME LSC 77 EXPORT_FILE_NAME ${core_generated_public_header_dir}/export.h 78 CUSTOM_CONTENT_FROM_VARIABLE core_export_custom_content) 79 80 # Common interface, mostly done this way to avoid double installation of headers 81 add_library(lscore_interface INTERFACE) 82 target_include_directories(lscore_interface 83 INTERFACE 84 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${core_public_header_base}> 85 $<BUILD_INTERFACE:${core_generated_public_header_base}> 86 $<INSTALL_INTERFACE:include>) 87 target_sources(lscore_interface 88 INTERFACE 89 FILE_SET public_headers 90 TYPE HEADERS 91 BASE_DIRS ${core_public_header_base} 92 FILES ${core_public_headers}) 93 target_sources(lscore_interface 94 INTERFACE 95 FILE_SET generated_public_headers 96 TYPE HEADERS 97 BASE_DIRS ${core_generated_public_header_base} 98 FILES ${core_generated_public_headers}) 99 100 # Specify everything that's common for both the static and the shared libraries 101 foreach(core_lib lscore_s lscore) 102 target_sources(${core_lib} 103 PRIVATE 104 ${core_source} 105 $<TARGET_OBJECTS:hashmap>) 106 set_target_properties(${core_lib} 107 PROPERTIES 108 VISIBILITY_INLINES_HIDDEN 1 109 C_VISIBILITY_PRESET hidden 110 LINKER_LANGUAGE C) 111 target_include_directories(${core_lib} 112 PUBLIC 113 $<TARGET_PROPERTY:lscore_interface,INTERFACE_INCLUDE_DIRECTORIES> 114 $<TARGET_PROPERTY:leutils,INTERFACE_INCLUDE_DIRECTORIES> 115 PRIVATE 116 $<TARGET_PROPERTY:hashmap,INTERFACE_INCLUDE_DIRECTORIES> 117 ) 118 target_link_libraries(${core_lib} PUBLIC leutils ${CMAKE_DL_LIBS}) 119 endforeach() 120 121 install(TARGETS lscore_interface lscore_s lscore 122 EXPORT LeSecCoreConfig 123 RUNTIME 124 DESTINATION ${CMAKE_INSTALL_BINDIR} 125 COMPONENT Libraries 126 LIBRARY 127 DESTINATION ${CMAKE_INSTALL_LIBDIR} 128 COMPONENT Libraries 129 NAMELINK_COMPONENT Development 130 ARCHIVE 131 DESTINATION ${CMAKE_INSTALL_LIBDIR} 132 COMPONENT Development 133 FILE_SET public_headers 134 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 135 COMPONENT Development 136 FILE_SET generated_public_headers 137 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 138 COMPONENT Development) 139 140 # Unit test of LSC_env_t 141 add_executable(unit_test_environment 142 environment.c 143 $<TARGET_OBJECTS:hashmap>) 144 target_compile_definitions(unit_test_environment 145 PRIVATE 146 LSC_STATIC_DEFINE 147 TEST_ENVIRONMENT) 148 target_include_directories(unit_test_environment 149 PRIVATE 150 $<TARGET_PROPERTY:lscore_interface,INTERFACE_INCLUDE_DIRECTORIES> 151 $<TARGET_PROPERTY:leutils,INTERFACE_INCLUDE_DIRECTORIES> 152 $<TARGET_PROPERTY:hashmap,INTERFACE_INCLUDE_DIRECTORIES>) 153 target_link_libraries(unit_test_environment PRIVATE lscore_s) 154 add_test(NAME unit_test_environment COMMAND unit_test_environment) 155 156 # Unit test of plugins 157 add_executable(unit_test_plugin plugin.c) 158 target_compile_definitions(unit_test_plugin 159 PRIVATE 160 LSC_STATIC_DEFINE 161 TEST_PLUGIN) 162 target_link_libraries(unit_test_plugin PRIVATE lscore_s) 163 add_test(NAME unit_test_plugin COMMAND unit_test_plugin) 164 165 # Unit test of object 166 add_executable(unit_test_object_and_operation object-and-operation.c) 167 target_compile_definitions(unit_test_object_and_operation 168 PRIVATE 169 LSC_STATIC_DEFINE 170 TEST_OBJECT TEST_OBJECT_DEBUG) 171 target_include_directories(unit_test_object_and_operation 172 PRIVATE 173 $<TARGET_PROPERTY:hashmap,INTERFACE_INCLUDE_DIRECTORIES>) 174 target_link_libraries(unit_test_object_and_operation PRIVATE lscore_s) 175 add_test(NAME unit_test_object_and_operation 176 COMMAND unit_test_object_and_operation) 177 178 # Unit test of registration 179 add_executable(unit_test_registration registration.c) 180 target_compile_definitions(unit_test_registration 181 PRIVATE 182 LSC_STATIC_DEFINE 183 TEST_REGISTRATION TEST_REGISTRATION_DEBUG) 184 target_include_directories(unit_test_registration 185 PRIVATE 186 $<TARGET_PROPERTY:hashmap,INTERFACE_INCLUDE_DIRECTORIES>) 187 target_link_libraries(unit_test_registration PRIVATE lscore_s) 188 add_test(NAME unit_test_registration COMMAND unit_test_registration)