1 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
2 project(gost-engine LANGUAGES C)
4 include(GNUInstallDirs)
8 find_package(OpenSSL 1.1.1 REQUIRED)
9 include_directories(${OPENSSL_INCLUDE_DIR})
11 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
12 add_compile_options(-Qunused-arguments)
13 elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
14 add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb)
15 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
16 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
17 add_definitions(-D_CRT_DEPRECATED_NO_WARNINGS)
18 add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
19 add_compile_options(/MP /WX /W4 /wd4100 /wd4267 /wd4206 /wd4706 /wd4244 /wd4115)
22 set(CMAKE_C_STANDARD 90)
24 include (TestBigEndian)
25 TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
27 message(STATUS "BIG_ENDIAN")
29 message(STATUS "LITTLE_ENDIAN")
30 add_definitions(-DL_ENDIAN)
33 set(BIN_DIRECTORY bin)
35 set(OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/${BIN_DIRECTORY})
37 #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
38 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
39 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
41 set(GOST_89_SOURCE_FILES
46 set(GOST_HASH_SOURCE_FILES
51 set(GOST_HASH_2012_SOURCE_FILES
55 gosthash2012_precalc.h
60 set(GOST_GRASSHOPPER_SOURCE_FILES
62 gost_grasshopper_core.h
63 gost_grasshopper_core.c
64 gost_grasshopper_defines.h
65 gost_grasshopper_defines.c
66 gost_grasshopper_math.h
67 gost_grasshopper_galois_precompiled.c
68 gost_grasshopper_precompiled.c
69 gost_grasshopper_cipher.h
70 gost_grasshopper_cipher.c
73 set(GOST_CORE_SOURCE_FILES
87 set(GOST_EC_SOURCE_FILES
92 set (GOST_OMAC_SOURCE_FILES
97 set(GOST_LIB_SOURCE_FILES
98 ${GOST_89_SOURCE_FILES}
99 ${GOST_HASH_SOURCE_FILES}
100 ${GOST_HASH_2012_SOURCE_FILES}
101 ${GOST_GRASSHOPPER_SOURCE_FILES}
102 ${GOST_EC_SOURCE_FILES}
103 ${GOST_OMAC_SOURCE_FILES}
106 set(GOST_ENGINE_SOURCE_FILES
107 ${GOST_CORE_SOURCE_FILES}
116 add_executable(test_curves test_curves.c)
117 target_link_libraries(test_curves gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
121 add_executable(test_context test_context.c)
122 target_link_libraries(test_context gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
123 add_test(NAME context
124 COMMAND test_context)
126 add_executable(test_grasshopper test_grasshopper.c)
127 target_link_libraries(test_grasshopper gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
128 add_test(NAME grasshopper
129 COMMAND test_grasshopper)
132 COMMAND perl run_tests
133 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
135 add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
136 set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
138 add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES})
139 set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost")
140 target_link_libraries(gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
142 set(GOST_SUM_SOURCE_FILES
146 add_executable(gostsum ${GOST_SUM_SOURCE_FILES})
147 target_link_libraries(gostsum gost_core)
149 set(GOST_12_SUM_SOURCE_FILES
153 add_executable(gost12sum ${GOST_12_SUM_SOURCE_FILES})
154 target_link_libraries(gost12sum gost_core)
156 add_executable(unit_expimp gost_keyexpimp.c e_gost_err.c)
157 target_compile_definitions(unit_expimp PUBLIC -DENABLE_UNIT_TESTS)
158 target_compile_definitions(unit_expimp PUBLIC -DOPENSSL_LOAD_CONF)
159 target_link_libraries(unit_expimp PUBLIC ${OPENSSL_CRYPTO_LIBRARY})
161 set_source_files_properties(tags PROPERTIES GENERATED true)
162 add_custom_target(tags
163 COMMAND ctags -R . ${OPENSSL_ROOT_DIR}
164 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
167 set(OPENSSL_ENGINES_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/engines-${OPENSSL_VERSION_MAJOR}_${OPENSSL_VERSION_MINOR})
168 set(OPENSSL_MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
170 install(TARGETS gost_engine gostsum gost12sum EXPORT GostEngineConfig
171 LIBRARY DESTINATION ${OPENSSL_ENGINES_INSTALL_DIR}
172 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
173 install(FILES gostsum.1 gost12sum.1 DESTINATION ${OPENSSL_MAN_INSTALL_DIR})
175 install(FILES $<TARGET_PDB_FILE:gost_engine> DESTINATION ${OPENSSL_ENGINES_INSTALL_DIR} OPTIONAL)
176 install(FILES $<TARGET_PDB_FILE:gostsum> $<TARGET_PDB_FILE:gost12sum> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)