-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
75 lines (64 loc) · 2.67 KB
/
CMakeLists.txt
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
# Copyright © 2023-2024 45gfg9 <[email protected]>
# 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 0.13)
# uncomment these lines to provide default values
# WARNING: password is stored in plain-text and can be dumped easily using `strings`
#
#set(SRUN_CONF_AUTH_URL "https://example.com")
#set(SRUN_CONF_DEFAULT_USERNAME "TanikazeAmane")
#set(SRUN_CONF_DEFAULT_PASSWORD "p4ssw@rd")
#set(SRUN_CONF_DEFAULT_CERTFILE "example-cert.pem")
#set(SRUN_CONF_DEFAULT_CLIENT_IP "0.0.0.0")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)
add_executable(${PROJECT_NAME} srun.c main.c)
# find current 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 ()
if (APPLE)
# have to handle OpenSSL on macOS to use Homebrew version
find_package(OpenSSL QUIET)
if (NOT OPENSSL_FOUND)
execute_process(
COMMAND brew --prefix
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
string(APPEND OPENSSL_ROOT_DIR "/opt/openssl")
endif ()
else ()
# have to configure libbsd on other platforms
find_package(PkgConfig REQUIRED)
pkg_check_modules(LibBSD REQUIRED IMPORTED_TARGET libbsd)
target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::LibBSD)
endif ()
string(TIMESTAMP SRUN_BUILD_TIME "%Y-%m-%d %H:%M:%S")
set(SRUN_VERSION "${CMAKE_PROJECT_VERSION}")
if (SRUN_CONF_DEFAULT_CERTFILE)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/${SRUN_CONF_DEFAULT_CERTFILE}" SRUN_CONF_DEFAULT_CERT)
string(REPLACE "\n" "\\n" SRUN_CONF_DEFAULT_CERT "${SRUN_CONF_DEFAULT_CERT}")
endif ()
if (NOT SRUN_CONF_DEFAULT_USERNAME AND SRUN_CONF_DEFAULT_PASSWORD)
message(WARNING "Cannot set password without username")
unset(SRUN_CONF_DEFAULT_PASSWORD)
endif ()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/srun_config.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/srun_config.h")
find_package(CURL REQUIRED)
find_package(cJSON REQUIRED)
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR} ${CJSON_INCLUDE_DIR} ${CURL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${OPENSSL_LIBRARIES} ${CJSON_LIBRARIES} ${CURL_LIBRARIES})