forked from Haivision/srt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindBotan.cmake
More file actions
142 lines (127 loc) · 4.23 KB
/
FindBotan.cmake
File metadata and controls
142 lines (127 loc) · 4.23 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
## This script was taken from https://github.com/Tectu/botan-cmake and modified slightly for SRT integration.
##
## This module will automagically download the tarball of the specified Botan version and invoke the configure.py
## python script to generate the amalgamation files (botan_all.cpp and botan_all.h).
##
## Usage:
## find_package(
## Botan 3.0.0
## COMPONENTS
## system_rng
## argon2
## sha3
## REQUIRED
## )
##
## target_link_libraries(
## MyTarget
## PRIVATE
## botan
## )
##
cmake_minimum_required(VERSION 3.19)
include(FetchContent)
# Find python
find_package(
Python
COMPONENTS
Interpreter
REQUIRED
)
# Assemble version string
set(Botan_VERSION_STRING ${Botan_FIND_VERSION_MAJOR}.${Botan_FIND_VERSION_MINOR}.${Botan_FIND_VERSION_PATCH})
# Assemble download URL
set(DOWNLOAD_URL https://github.com/randombit/botan/archive/refs/tags/${Botan_VERSION_STRING}.tar.gz)
# Just do a dummy download to see whether we can download the tarball
file(
DOWNLOAD
${DOWNLOAD_URL}
STATUS download_status
)
if (NOT download_status EQUAL 0)
message(FATAL_ERROR "Could not download Botan tarball (status = ${download_status}): ${DOWNLOAD_URL}")
endif()
# Download the tarball
FetchContent_Declare(
botan_upstream
URL ${DOWNLOAD_URL}
DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_MakeAvailable(botan_upstream)
# Heavy lifting by cmake
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Botan DEFAULT_MSG Botan_VERSION_STRING)
## Function to generate a target named 'TARGET_NAME' with specific Botan modules enabled.
function(botan_generate TARGET_NAME MODULES)
# The last N arguments are considered to be the modules list.
# Here, we collect those in a list and join them with a comma separator ready to be passed to the configure.py script.
foreach(module_index RANGE 1 ${ARGC}-2)
list(APPEND modules_list ${ARGV${module_index}})
endforeach()
list(JOIN modules_list "," ENABLE_MODULES_LIST)
# Determine botan compiler ID (--cc parameter of configure.py)
set(BOTAN_COMPILER_ID ${CMAKE_CXX_COMPILER_ID})
string(TOLOWER ${BOTAN_COMPILER_ID} BOTAN_COMPILER_ID)
if (BOTAN_COMPILER_ID STREQUAL "gnu")
set(BOTAN_COMPILER_ID "gcc")
endif()
# Run the configure.py script
add_custom_command(
OUTPUT botan_all.cpp botan_all.h
COMMENT "Generating Botan amalgamation files botan_all.cpp and botan_all.h"
COMMAND ${Python_EXECUTABLE}
${botan_upstream_SOURCE_DIR}/configure.py
--quiet
--cc-bin=${CMAKE_CXX_COMPILER}
--cc=${BOTAN_COMPILER_ID}
--disable-cc-tests
--os=${BOTAN_OS}
--cpu=${BOTAN_CPU}
--disable-shared
--amalgamation
--with-build-dir=botan
--minimized-build
--enable-modules=${ENABLE_MODULES_LIST}
)
# Create target
set(TARGET ${TARGET_NAME})
add_library(${TARGET} STATIC)
target_sources(
${TARGET}
PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/botan_all.h
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/botan_all.cpp
)
target_include_directories(
${TARGET}
INTERFACE
${CMAKE_CURRENT_BINARY_DIR}
)
set_target_properties(
${TARGET}
PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
add_custom_command(
TARGET ${TARGET_NAME}
COMMENT "Copying build.h file"
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_BINARY_DIR}/botan/build/build.h"
"${CMAKE_CURRENT_BINARY_DIR}/botan/build.h"
)
add_custom_command(
TARGET ${TARGET_NAME}
COMMENT "Copying compiler.h file"
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_BINARY_DIR}/botan/build/include/botan/compiler.h"
"${CMAKE_CURRENT_BINARY_DIR}/botan/compiler.h"
)
add_custom_command(
TARGET ${TARGET_NAME}
COMMENT "Copying ffi.h file"
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_BINARY_DIR}/botan/build/include/botan/ffi.h"
"${CMAKE_CURRENT_BINARY_DIR}/botan/ffi.h"
)
endfunction()