blob: e6034a14c9f5af5170921c8df74bfa1a69d88e57 (
plain)
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
143
|
# CMakeList.txt : CMake project for noscrypt, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.10)
project(noscrypt C)
option(BUILD_TESTS "Build tests" TRUE)
set(NOSCRYPT_SRCS
"src/noscrypt.c"
)
set(NOSCRYPT_HEADERS
"src/noscrypt.h"
)
include_directories(include)
#static/shared library
add_library(${CMAKE_PROJECT_NAME} SHARED ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS})
add_library(${CMAKE_PROJECT_NAME}_static STATIC ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS})
#Setup the compiler options for c90 shared library
set(CMAKE_C_STANDARD 90)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC c_std_90)
#if debug
add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
#when building we are in libary mode, we need to export our symbols
add_compile_definitions(NOSCRYPT_EXPORTING)
#setup flags for windows compilation
if(MSVC)
#global windows cl flags
add_compile_options(
/sdl #enable additional security checks
/TC #compile as c
/GS #buffer security check
$<$<CONFIG:Debug>:/FC> #show full path in diagnostics
$<$<CONFIG:Debug>:/showIncludes> #show a list of all included header files during build
$<$<CONFIG:Debug>:/wd4820> #disable warnings for struct padding and spectre mitigation wuen WX is enabled
$<$<CONFIG:Debug>:/wd5045> #disable warnings for spectre mitigation insertion
#for debug configs
$<$<CONFIG:Debug>:/options:strict>
$<$<CONFIG:Debug>:/Wall> #enable all warnings
$<$<CONFIG:Debug>:/WX> #warnings as errors (only for our project)
$<$<CONFIG:Debug>:/Zi> #enable rich debug info
$<$<CONFIG:Debug>:/Zo>
)
#set build macros
add_compile_definitions(
$<$<CONFIG:DEBUG>:DEBUG>
$<$<CONFIG:RELEASE>:RELEASE>
)
#configure gcc flags
elseif(CMAKE_COMPILER_IS_GNUCC)
add_compile_options(
-Wextra
-fstack-protector
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-Og>
$<$<CONFIG:Debug>:-Wall>
$<$<CONFIG:Debug>:-Werror>
$<$<CONFIG:Debug>:-Wall>
$<$<CONFIG:Debug>:-pedantic>
)
endif()
# Setup secp256k1 shared libary
unset(SECP256K1_LIB CACHE)
find_library(SECP256K1_LIB
NAMES secp256k1 libsecp256k1 lib_secp256k1
PATHS ${LOCAL_SECP256K1_DIR}/src
)
if(NOT SECP256K1_LIB)
message(FATAL_ERROR "secp256k1 library not found on local system")
endif()
message(STATUS "secp256k1 library found at ${SECP256K1_LIB}")
target_link_libraries(${CMAKE_PROJECT_NAME} ${SECP256K1_LIB})
#link mbedtls and mbedcrypto shared libraries
unset(MBEDCRYPTO_LIB CACHE)
unset(MBEDTLS_LIB CACHE)
find_library(MBEDTLS_LIB
NAMES mbedtls libmbedtls
PATHS ${LOCAL_MBEDTLS_DIR}/library
)
find_library(MBEDCRYPTO_LIB
NAMES mbedcrypto libmbedcrypto
PATHS ${LOCAL_MBEDTLS_DIR}/library
)
if(NOT MBEDCRYPTO_LIB)
message(FATAL_ERROR "mbedcrypto library not found on local system")
endif()
if(NOT MBEDTLS_LIB)
message(FATAL_ERROR "mbedtls library not found on local system")
endif()
message(STATUS "mbedtls library found at ${MBEDTLS_LIB}")
message(STATUS "mbedcrypto library found at ${MBEDCRYPTO_LIB}")
target_link_libraries(${CMAKE_PROJECT_NAME} ${MBEDCRYPTO_LIB} ${MBEDTLS_LIB})
#TESTS
if(BUILD_TESTS)
#add test executable and link to library
add_executable(nctest tests/test.c)
target_link_libraries(nctest ${CMAKE_PROJECT_NAME})
#link mbedtls crypto shared library directly
target_link_libraries(nctest ${MBEDCRYPTO_LIB} ${MBEDTLS_LIB})
target_include_directories(nctest PRIVATE "src")
#enable c11 for testing
target_compile_features(nctest PRIVATE c_std_11)
endif()
# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
|