-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
101 lines (87 loc) · 3.82 KB
/
CMakeLists.txt
File metadata and controls
101 lines (87 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright © 2023-2025 45gfg9 <45gfg9@45gfg9.net>
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See the LICENSE file for more details.
cmake_minimum_required(VERSION 3.20)
project(srun C)
project(srun VERSION 1.0.0)
set(SRUN_CRYPTO "openssl" CACHE STRING "The crypto library to use")
set_property(CACHE SRUN_CRYPTO PROPERTY STRINGS "openssl" "mbedtls" "self")
string(TOLOWER "${SRUN_CRYPTO}" SRUN_CRYPTO)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS OFF)
add_executable(${PROJECT_NAME} srun.c main.c)
# ---- Compiler options ----
target_compile_definitions(${PROJECT_NAME} PRIVATE _GNU_SOURCE)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall -Wextra
$<$<CONFIG:Debug>:-pedantic -fsanitize=address,undefined -fstack-protector-all -fno-omit-frame-pointer -ggdb>
$<$<AND:$<CONFIG:Debug>,$<PLATFORM_ID:Linux>>:-fsanitize=leak>
$<$<CONFIG:Release>:-O3>
)
target_include_directories(${PROJECT_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/platform"
)
# ---- Git revision ----
find_package(Git)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always --tags --dirty
OUTPUT_VARIABLE SRUN_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif ()
string(TIMESTAMP SRUN_BUILD_TIME "%Y-%m-%d %H:%M:%S")
set(SRUN_VERSION "${CMAKE_PROJECT_VERSION}")
# ---- Config header ----
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/srun_config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/srun_config.h"
)
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
# ---- libbsd ----
if (NOT (APPLE OR BSD))
find_library(LIBBSD_LIB NAMES bsd libbsd)
find_path(LIBBSD_INCLUDE_DIRS bsd/readpassphrase.h)
if (LIBBSD_LIB AND LIBBSD_INCLUDE_DIRS)
message(STATUS "Found libbsd: ${LIBBSD_LIB}")
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBBSD_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBBSD_LIB})
else ()
message(WARNING "libbsd not found, will use potentially insecure fallback implementation")
endif ()
endif ()
# ---- libcurl ----
find_package(CURL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)
target_sources(${PROJECT_NAME} PRIVATE platform/libcurl.c)
# ---- cJSON ----
find_package(cJSON REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${CJSON_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${CJSON_LIBRARIES})
target_sources(${PROJECT_NAME} PRIVATE platform/cjson.c)
# ---- crypto (mbedtls / openssl / self) ----
find_library(MbedCrypto_LIB mbedcrypto)
find_path(MbedCrypto_INCLUDE_DIR mbedtls/md.h)
find_package(OpenSSL COMPONENTS Crypto)
if (MbedCrypto_LIB AND MbedCrypto_INCLUDE_DIR AND (NOT OpenSSL_FOUND OR SRUN_CRYPTO STREQUAL "mbedtls"))
message(STATUS "Found MbedTLS: ${MbedCrypto_LIB}")
target_include_directories(${PROJECT_NAME} PRIVATE ${MbedCrypto_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${MbedCrypto_LIB})
target_sources(${PROJECT_NAME} PRIVATE platform/mbedtls.c)
elseif (OpenSSL_FOUND AND NOT (SRUN_CRYPTO STREQUAL "self"))
if (NOT (SRUN_CRYPTO STREQUAL "openssl"))
message(WARNING "Could not find specified crypto library: ${SRUN_CRYPTO}. Using OpenSSL instead")
endif ()
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::Crypto)
target_sources(${PROJECT_NAME} PRIVATE platform/openssl.c)
else ()
if (NOT (SRUN_CRYPTO STREQUAL "self"))
message(WARNING "Could not find crypto library: ${SRUN_CRYPTO}")
endif ()
message(STATUS "Using self-implemented crypto functions")
target_sources(${PROJECT_NAME} PRIVATE platform/md.c)
endif ()