]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - CMakeLists.txt
Merge pull request #166 from levitte/cleanup-tests
[openssl-gost/engine.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
2 project(gost-engine LANGUAGES C)
3
4 include(GNUInstallDirs)
5 include(CheckLibraryExists)
6 include(CheckFunctionExists)
7
8 enable_testing()
9
10 find_package(OpenSSL 1.1.1 REQUIRED)
11 include_directories(${OPENSSL_INCLUDE_DIR})
12
13 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
14  add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Qunused-arguments)
15 elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
16  add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb)
17 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
18  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
19  add_definitions(-D_CRT_DEPRECATED_NO_WARNINGS)
20  add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
21  add_compile_options(/MP /WX /W4 /wd4100 /wd4267 /wd4206 /wd4706 /wd4244 /wd4115)
22 endif()
23
24 if (ASAN)
25   message(STATUS "address sanitizer enabled")
26   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g3 -fno-omit-frame-pointer")
27 endif()
28
29 set(CMAKE_C_STANDARD 90)
30 CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME_C)
31 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_CLOCK_GETTIME_RT)
32 if(HAVE_CLOCK_GETTIME_RT AND NOT HAVE_CLOCK_GETTIME_C)
33   set(CLOCK_GETTIME_LIB rt)
34 endif()
35
36 include (TestBigEndian)
37 TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
38 if(IS_BIG_ENDIAN)
39  message(STATUS "BIG_ENDIAN")
40 else()
41  message(STATUS "LITTLE_ENDIAN")
42  add_definitions(-DL_ENDIAN)
43 endif()
44
45 set(BIN_DIRECTORY bin)
46
47 # Same soversion as OpenSSL
48 set(GOST_SOVERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}")
49
50 set(OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BIN_DIRECTORY})
51
52 #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
53 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
54 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
55
56 # Remove when https://gitlab.kitware.com/cmake/cmake/issues/18525 is addressed
57 set(OPENSSL_ENGINES_DIR "" CACHE PATH "OpenSSL Engines Directory")
58 if ("${OPENSSL_ENGINES_DIR}" STREQUAL "")
59         include(FindPkgConfig)
60         pkg_get_variable(OPENSSL_ENGINES_DIR libcrypto enginesdir)
61         if ("${OPENSSL_ENGINES_DIR}" STREQUAL "")
62                 message( FATAL_ERROR "Unable to discover the OpenSSL engines directory. Provide the path using -DOPENSSL_ENGINES_DIR" )
63         endif()
64 endif()
65
66 set(GOST_89_SOURCE_FILES
67         gost89.c
68         gost89.h
69         )
70
71 set(GOST_HASH_SOURCE_FILES
72         gosthash.c
73         gosthash.h
74         )
75
76 set(GOST_HASH_2012_SOURCE_FILES
77         gosthash2012.c
78         gosthash2012.h
79         gosthash2012_const.h
80         gosthash2012_precalc.h
81         gosthash2012_ref.h
82         gosthash2012_sse2.h
83         )
84
85 set(GOST_GRASSHOPPER_SOURCE_FILES
86         gost_grasshopper.h
87         gost_grasshopper_core.h
88         gost_grasshopper_core.c
89         gost_grasshopper_defines.h
90         gost_grasshopper_defines.c
91         gost_grasshopper_math.h
92         gost_grasshopper_galois_precompiled.c
93         gost_grasshopper_precompiled.c
94         gost_grasshopper_cipher.h
95         gost_grasshopper_cipher.c
96         )
97
98 set(GOST_CORE_SOURCE_FILES
99         e_gost_err.c
100         e_gost_err.h
101         gost_asn1.c
102         gost_crypt.c
103         gost_ctl.c
104         gost_eng.c
105         gost_keywrap.c
106         gost_keywrap.h
107         gost_lcl.h
108         gost_params.c
109         gost_keyexpimp.c
110         )
111
112 set(GOST_EC_SOURCE_FILES
113         gost_ec_keyx.c
114         gost_ec_sign.c
115         )
116
117 set (GOST_OMAC_SOURCE_FILES
118         gost_omac.c
119         gost_omac_acpkm.c
120         )
121
122 set(GOST_LIB_SOURCE_FILES
123         ${GOST_89_SOURCE_FILES}
124         ${GOST_HASH_SOURCE_FILES}
125         ${GOST_HASH_2012_SOURCE_FILES}
126         ${GOST_GRASSHOPPER_SOURCE_FILES}
127         ${GOST_EC_SOURCE_FILES}
128         ${GOST_OMAC_SOURCE_FILES}
129         )
130
131 set(GOST_ENGINE_SOURCE_FILES
132         ${GOST_CORE_SOURCE_FILES}
133         gost_ameth.c
134         gost_md.c
135         gost_md2012.c
136         gost_pmeth.c
137         gost_omac.c
138         gost_omac_acpkm.c
139         )
140
141 add_executable(test_digest test_digest.c)
142 target_link_libraries(test_digest gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
143 add_test(NAME digest
144         COMMAND test_digest)
145
146 add_executable(test_curves test_curves.c)
147 target_link_libraries(test_curves gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
148 add_test(NAME curves
149         COMMAND test_curves)
150
151 add_executable(test_params test_params.c)
152 target_link_libraries(test_params gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
153 add_test(NAME parameters
154         COMMAND test_params)
155
156 add_executable(test_sign test_sign.c)
157 target_link_libraries(test_sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
158 add_test(NAME sign/verify
159         COMMAND test_sign)
160
161 add_executable(test_tls test_tls.c)
162 target_link_libraries(test_tls gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
163 add_test(NAME TLS
164         COMMAND test_tls)
165
166 add_executable(test_context test_context.c)
167 target_link_libraries(test_context gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
168 add_test(NAME context
169         COMMAND test_context)
170
171 add_executable(test_grasshopper test_grasshopper.c)
172 target_link_libraries(test_grasshopper gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
173 add_test(NAME grasshopper
174         COMMAND test_grasshopper)
175
176 add_executable(test_keyexpimp test_keyexpimp.c)
177 #target_compile_definitions(test_keyexpimp PUBLIC -DOPENSSL_LOAD_CONF)
178 target_link_libraries(test_keyexpimp gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
179 add_test(NAME keyexpimp
180         COMMAND test_keyexpimp)
181
182 add_executable(test_gost89 test_gost89.c)
183 target_link_libraries(test_gost89 gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
184 add_test(NAME gost89
185         COMMAND test_gost89)
186
187 if(NOT ASAN)
188 add_test(NAME engine
189         COMMAND perl run_tests
190         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
191 set_tests_properties(engine PROPERTIES ENVIRONMENT
192         "OPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR};OPENSSL_ENGINES=${OUTPUT_DIRECTORY};OPENSSL_CONF=${CMAKE_SOURCE_DIR}/test/empty.cnf")
193 endif()
194
195 add_executable(sign benchmark/sign.c)
196 target_link_libraries(sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} ${CLOCK_GETTIME_LIB})
197
198 # All that may need to load just built engine will have path to it defined.
199 set(BINARY_TESTS_TARGETS
200         test_digest
201         test_curves
202         test_params
203         test_sign
204         test_context
205         test_grasshopper
206         test_keyexpimp
207         test_gost89
208         test_tls
209         )
210 set_property(TARGET ${BINARY_TESTS_TARGETS} APPEND PROPERTY COMPILE_DEFINITIONS ENGINE_DIR="${OUTPUT_DIRECTORY}")
211
212 add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
213 set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
214
215 add_library(gost_engine SHARED ${GOST_ENGINE_SOURCE_FILES})
216 set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost")
217 set_target_properties(gost_engine PROPERTIES VERSION ${GOST_SOVERSION} SOVERSION ${GOST_SOVERSION})
218 target_link_libraries(gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
219
220 set(GOST_SUM_SOURCE_FILES
221         gostsum.c
222         )
223
224 add_executable(gostsum ${GOST_SUM_SOURCE_FILES})
225 target_link_libraries(gostsum gost_core)
226
227 set(GOST_12_SUM_SOURCE_FILES
228         gost12sum.c
229         )
230
231 add_executable(gost12sum ${GOST_12_SUM_SOURCE_FILES})
232 target_link_libraries(gost12sum gost_core)
233
234 set_source_files_properties(tags PROPERTIES GENERATED true)
235 add_custom_target(tags
236     COMMAND ctags -R . ${OPENSSL_ROOT_DIR}
237     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
238
239 add_executable(test_tlstree test_tlstree.c)
240 target_link_libraries(test_tlstree PUBLIC ${OPENSSL_CRYPTO_LIBRARY})
241
242 # install
243 set(OPENSSL_MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
244
245 install(TARGETS gost_engine gostsum gost12sum EXPORT GostEngineConfig
246         LIBRARY  DESTINATION ${OPENSSL_ENGINES_DIR}
247         RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})
248 install(FILES gostsum.1 gost12sum.1 DESTINATION ${OPENSSL_MAN_INSTALL_DIR})
249 if (MSVC)
250  install(FILES $<TARGET_PDB_FILE:gost_engine> DESTINATION ${OPENSSL_ENGINES_DIR} OPTIONAL)
251  install(FILES $<TARGET_PDB_FILE:gostsum> $<TARGET_PDB_FILE:gost12sum> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
252 endif()