/ CMakeLists.txt
CMakeLists.txt
1 # SPDX-FileCopyrightText: 2023-2025 Le'Sec Core collective 2 # 3 # SPDX-License-Identifier: LGPL-3.0-or-later 4 5 cmake_minimum_required(VERSION 3.23) 6 7 # Get the actual version from 'git describe', and reformat it into a project 8 # version number by ensuring that it's a three number version, and then add 9 # the number of commits since the latest reachable tag as a fourth (tweak) 10 # number. 11 # The idea came from https://www.hezmatt.org/~mpalmer/blog/2024/11/23/your-release-process-sucks.html 12 set(current_description "$Format:%(describe:tags=true,match=v[0-9]*.[0-9]*)$") 13 if(current_description MATCHES [[^\$Format]]) 14 execute_process( 15 COMMAND git describe --tags --match "v[0-9]*.[0-9]*" 16 OUTPUT_VARIABLE current_description 17 OUTPUT_STRIP_TRAILING_WHITESPACE 18 ) 19 endif() 20 if(current_description MATCHES [[^v([0-9.]+)-([0-9]+)-g[0-9a-f]+$]]) 21 set(current_version ${CMAKE_MATCH_1}) 22 set(current_commits_n ${CMAKE_MATCH_2}) 23 if (current_version MATCHES [[^[0-9]+\.[0-9]+$]]) 24 # The current version is vx.y, make it vx.y.0 25 set(current_version "${current_version}.0") 26 endif() 27 # Add the number of commits as a fourth version number, representing the 28 # current local development (akin to build number, say?), unless it's zero 29 if (NOT current_commits_n EQUAL 0) 30 set(current_version "${current_version}.${current_commits_n}") 31 endif() 32 else() 33 string(REGEX REPLACE [[^v]] [[]] current_version ${current_description}) 34 endif() 35 message(STATUS "Project version is determined to be ${current_version} (from ${current_description})") 36 37 project( 38 lesec-core 39 VERSION ${current_version} 40 DESCRIPTION "Le'Sec Core is a collection of core libraries that are intended to work together to provide basic security functionality, covering related objects and operations. Applications and protocols are covered in other projects." 41 LANGUAGES C) 42 set(CMAKE_C_STANDARD 99) 43 44 # Global CMake stuff we use 45 46 enable_testing() 47 include(GNUInstallDirs) 48 include(FetchContent) 49 50 # Global facts 51 52 set(LSC_PLUGIN_DIR ${CMAKE_INSTALL_PREFIX}) 53 cmake_path(APPEND LSC_PLUGIN_DIR ${CMAKE_INSTALL_LIBDIR} LeSec plugins) 54 set(LSC_PLUGIN_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) 55 message(STATUS "The Plugin directory is ${LSC_PLUGIN_DIR}") 56 57 # Declarations of external dependencies 58 59 FetchContent_Declare( 60 hashmap 61 GIT_REPOSITORY https://github.com/tidwall/hashmap.c.git 62 GIT_TAG v0.8.0 63 ) 64 65 # Get all the things this project depends on 66 67 FetchContent_MakeAvailable(hashmap) 68 find_package(LeUtils QUIET REQUIRED) 69 70 # Build all libraries in one place, for convenience 71 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 72 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 73 # Build all runtimes in one place, for convenience 74 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 75 76 # hashmap isn't a CMake project. As a matter of fact, it only contains 77 # source files, directly usable here. 78 add_library(hashmap OBJECT ${hashmap_SOURCE_DIR}/hashmap.c) 79 set_target_properties(hashmap 80 PROPERTIES 81 VISIBILITY_INLINES_HIDDEN 1 82 C_VISIBILITY_PRESET hidden 83 LINKER_LANGUAGE C) 84 target_include_directories(hashmap PUBLIC ${hashmap_SOURCE_DIR}) 85 86 # Add all the sources, how to build them, and how to install them 87 88 add_subdirectory(src/core) 89 add_subdirectory(src/crypto) 90 91 # Add exports 92 93 install(EXPORT LeSecCoreConfig 94 DESTINATION cmake 95 NAMESPACE LeSecCore:: 96 EXPORT_LINK_INTERFACE_LIBRARIES) 97 98 export(EXPORT LeSecCoreConfig 99 NAMESPACE LeSecCore::)