]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - CMakeLists.txt
Merge pull request #94 from candrews/cmake-improvements
[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
6 enable_testing()
7
8 find_package(OpenSSL 1.1.1 REQUIRED)
9 include_directories(${OPENSSL_INCLUDE_DIR})
10
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)
20 endif()
21
22 set(CMAKE_C_STANDARD 90)
23
24 include (TestBigEndian)
25 TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
26 if(IS_BIG_ENDIAN)
27  message(STATUS "BIG_ENDIAN")
28 else()
29  message(STATUS "LITTLE_ENDIAN")
30  add_definitions(-DL_ENDIAN)
31 endif()
32
33 set(BIN_DIRECTORY bin)
34
35 set(OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BIN_DIRECTORY})
36
37 #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
38 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
39 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
40
41 # Remove when https://gitlab.kitware.com/cmake/cmake/issues/18525 is addressed
42 set(OPENSSL_ENGINES_DIR "" CACHE PATH "OpenSSL Engines Directory")
43 if ("${OPENSSL_ENGINES_DIR}" STREQUAL "")
44         include(FindPkgConfig)
45         pkg_get_variable(OPENSSL_ENGINES_DIR libcrypto enginesdir)
46         if ("${OPENSSL_ENGINES_DIR}" STREQUAL "")
47                 message( FATAL_ERROR "Unable to discover the OpenSSL engines directory. Provide the path using -DOPENSSL_ENGINES_DIR" )
48         endif()
49 endif()
50
51 set(GOST_89_SOURCE_FILES
52         gost89.c
53         gost89.h
54         )
55
56 set(GOST_HASH_SOURCE_FILES
57         gosthash.c
58         gosthash.h
59         )
60
61 set(GOST_HASH_2012_SOURCE_FILES
62         gosthash2012.c
63         gosthash2012.h
64         gosthash2012_const.h
65         gosthash2012_precalc.h
66         gosthash2012_ref.h
67         gosthash2012_sse2.h
68         )
69
70 set(GOST_GRASSHOPPER_SOURCE_FILES
71         gost_grasshopper.h
72         gost_grasshopper_core.h
73         gost_grasshopper_core.c
74         gost_grasshopper_defines.h
75         gost_grasshopper_defines.c
76         gost_grasshopper_math.h
77         gost_grasshopper_galois_precompiled.c
78         gost_grasshopper_precompiled.c
79         gost_grasshopper_cipher.h
80         gost_grasshopper_cipher.c
81         )
82
83 set(GOST_CORE_SOURCE_FILES
84         e_gost_err.c
85         e_gost_err.h
86         gost_asn1.c
87         gost_crypt.c
88         gost_ctl.c
89         gost_eng.c
90         gost_keywrap.c
91         gost_keywrap.h
92         gost_lcl.h
93         gost_params.c
94         gost_keyexpimp.c
95         )
96
97 set(GOST_EC_SOURCE_FILES
98         gost_ec_keyx.c
99         gost_ec_sign.c
100         )
101
102 set (GOST_OMAC_SOURCE_FILES
103         gost_omac.c
104         gost_omac_acpkm.c
105         )
106
107 set(GOST_LIB_SOURCE_FILES
108         ${GOST_89_SOURCE_FILES}
109         ${GOST_HASH_SOURCE_FILES}
110         ${GOST_HASH_2012_SOURCE_FILES}
111         ${GOST_GRASSHOPPER_SOURCE_FILES}
112         ${GOST_EC_SOURCE_FILES}
113         ${GOST_OMAC_SOURCE_FILES}
114         )
115
116 set(GOST_ENGINE_SOURCE_FILES
117         ${GOST_CORE_SOURCE_FILES}
118         gost_ameth.c
119         gost_md.c
120         gost_md2012.c
121         gost_pmeth.c
122         gost_omac.c
123         gost_omac_acpkm.c
124         )
125
126 add_executable(test_curves test_curves.c)
127 target_link_libraries(test_curves gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
128 add_test(NAME curves
129         COMMAND test_curves)
130
131 add_executable(test_context test_context.c)
132 target_link_libraries(test_context gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
133 add_test(NAME context
134         COMMAND test_context)
135
136 add_executable(test_grasshopper test_grasshopper.c)
137 target_link_libraries(test_grasshopper gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
138 add_test(NAME grasshopper
139         COMMAND test_grasshopper)
140
141 add_test(NAME engine
142          COMMAND perl run_tests
143          WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
144 set_tests_properties(engine PROPERTIES ENVIRONMENT OPENSSL_ENGINES=${OUTPUT_DIRECTORY})
145
146 add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
147 set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
148
149 add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES})
150 set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost")
151 target_link_libraries(gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
152
153 set(GOST_SUM_SOURCE_FILES
154         gostsum.c
155         )
156
157 add_executable(gostsum ${GOST_SUM_SOURCE_FILES})
158 target_link_libraries(gostsum gost_core)
159
160 set(GOST_12_SUM_SOURCE_FILES
161         gost12sum.c
162         )
163
164 add_executable(gost12sum ${GOST_12_SUM_SOURCE_FILES})
165 target_link_libraries(gost12sum gost_core)
166
167 add_executable(unit_expimp gost_keyexpimp.c e_gost_err.c)
168 target_compile_definitions(unit_expimp PUBLIC -DENABLE_UNIT_TESTS)
169 target_compile_definitions(unit_expimp PUBLIC -DOPENSSL_LOAD_CONF)
170 target_link_libraries(unit_expimp PUBLIC ${OPENSSL_CRYPTO_LIBRARY})
171
172 set_source_files_properties(tags PROPERTIES GENERATED true)
173 add_custom_target(tags
174     COMMAND ctags -R . ${OPENSSL_ROOT_DIR}
175     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
176
177 # install
178 set(OPENSSL_MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
179
180 install(TARGETS gost_engine gostsum gost12sum EXPORT GostEngineConfig
181         LIBRARY  DESTINATION ${OPENSSL_ENGINES_DIR}
182         RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})
183 install(FILES gostsum.1 gost12sum.1 DESTINATION ${OPENSSL_MAN_INSTALL_DIR})
184 if (MSVC)
185  install(FILES $<TARGET_PDB_FILE:gost_engine> DESTINATION ${OPENSSL_ENGINES_DIR} OPTIONAL)
186  install(FILES $<TARGET_PDB_FILE:gostsum> $<TARGET_PDB_FILE:gost12sum> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
187 endif()