1include_directories(. ../include)
2
3if(APPLE)
4  if (${ARCH} STREQUAL "x86")
5    set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
6  endif()
7  set(PERLASM_STYLE macosx)
8  set(ASM_EXT S)
9  enable_language(ASM)
10elseif(UNIX)
11  if (${ARCH} STREQUAL "aarch64")
12    # The "armx" Perl scripts look for "64" in the style argument
13    # in order to decide whether to generate 32- or 64-bit asm.
14    set(PERLASM_STYLE linux64)
15  elseif (${ARCH} STREQUAL "arm")
16    set(PERLASM_STYLE linux32)
17  elseif (${ARCH} STREQUAL "x86")
18    set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
19    set(PERLASM_STYLE elf)
20  else()
21    set(PERLASM_STYLE elf)
22  endif()
23  set(ASM_EXT S)
24  enable_language(ASM)
25else()
26  if (CMAKE_CL_64)
27    message("Using nasm")
28    set(PERLASM_STYLE nasm)
29  else()
30    message("Using win32n")
31    set(PERLASM_STYLE win32n)
32    set(PERLASM_FLAGS "-DOPENSSL_IA32_SSE2")
33  endif()
34
35  # On Windows, we use the NASM output, specifically built with Yasm.
36  set(ASM_EXT asm)
37  enable_language(ASM_NASM)
38endif()
39
40function(perlasm dest src)
41  add_custom_command(
42    OUTPUT ${dest}
43    COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} > ${dest}
44    DEPENDS
45    ${src}
46    ${PROJECT_SOURCE_DIR}/crypto/perlasm/arm-xlate.pl
47    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl
48    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86asm.pl
49    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86gas.pl
50    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86masm.pl
51    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86nasm.pl
52    WORKING_DIRECTORY .
53  )
54endfunction()
55
56if (${ARCH} STREQUAL "x86_64")
57  set(
58    CRYPTO_ARCH_SOURCES
59
60    cpu-x86_64-asm.${ASM_EXT}
61    cpu-intel.c
62  )
63endif()
64
65if (${ARCH} STREQUAL "x86")
66  set(
67    CRYPTO_ARCH_SOURCES
68
69    cpu-x86-asm.${ASM_EXT}
70    cpu-intel.c
71  )
72endif()
73
74if (${ARCH} STREQUAL "arm")
75  set(
76    CRYPTO_ARCH_SOURCES
77
78    cpu-arm.c
79    cpu-arm-asm.S
80  )
81endif()
82
83if (${ARCH} STREQUAL "aarch64")
84  set(
85    CRYPTO_ARCH_SOURCES
86
87    cpu-arm.c
88  )
89endif()
90
91# Level 0.1 - depends on nothing outside this set.
92add_subdirectory(stack)
93add_subdirectory(lhash)
94add_subdirectory(err)
95add_subdirectory(buf)
96add_subdirectory(base64)
97add_subdirectory(bytestring)
98
99# Level 0.2 - depends on nothing but itself
100add_subdirectory(sha)
101add_subdirectory(md4)
102add_subdirectory(md5)
103add_subdirectory(modes)
104add_subdirectory(aes)
105add_subdirectory(des)
106add_subdirectory(rc4)
107add_subdirectory(conf)
108add_subdirectory(chacha)
109add_subdirectory(poly1305)
110
111# Level 1, depends only on 0.*
112add_subdirectory(digest)
113add_subdirectory(cipher)
114add_subdirectory(rand)
115add_subdirectory(bio)
116add_subdirectory(bn)
117add_subdirectory(obj)
118add_subdirectory(asn1)
119
120# Level 2
121add_subdirectory(engine)
122add_subdirectory(dh)
123add_subdirectory(dsa)
124add_subdirectory(rsa)
125add_subdirectory(ec)
126add_subdirectory(ecdh)
127add_subdirectory(ecdsa)
128add_subdirectory(hmac)
129
130# Level 3
131add_subdirectory(cmac)
132add_subdirectory(evp)
133add_subdirectory(hkdf)
134add_subdirectory(pem)
135add_subdirectory(x509)
136add_subdirectory(x509v3)
137
138# Level 4
139add_subdirectory(pkcs8)
140
141# Test support code
142add_subdirectory(test)
143
144add_library(
145  crypto
146
147  crypto.c
148  directory_posix.c
149  directory_win.c
150  ex_data.c
151  mem.c
152  refcount_c11.c
153  refcount_lock.c
154  thread.c
155  thread_none.c
156  thread_pthread.c
157  thread_win.c
158  time_support.c
159
160  ${CRYPTO_ARCH_SOURCES}
161
162  $<TARGET_OBJECTS:stack>
163  $<TARGET_OBJECTS:lhash>
164  $<TARGET_OBJECTS:err>
165  $<TARGET_OBJECTS:base64>
166  $<TARGET_OBJECTS:bytestring>
167  $<TARGET_OBJECTS:sha>
168  $<TARGET_OBJECTS:md4>
169  $<TARGET_OBJECTS:md5>
170  $<TARGET_OBJECTS:digest>
171  $<TARGET_OBJECTS:cipher>
172  $<TARGET_OBJECTS:modes>
173  $<TARGET_OBJECTS:aes>
174  $<TARGET_OBJECTS:des>
175  $<TARGET_OBJECTS:rc4>
176  $<TARGET_OBJECTS:conf>
177  $<TARGET_OBJECTS:chacha>
178  $<TARGET_OBJECTS:poly1305>
179  $<TARGET_OBJECTS:buf>
180  $<TARGET_OBJECTS:bn>
181  $<TARGET_OBJECTS:bio>
182  $<TARGET_OBJECTS:rand>
183  $<TARGET_OBJECTS:obj>
184  $<TARGET_OBJECTS:asn1>
185  $<TARGET_OBJECTS:engine>
186  $<TARGET_OBJECTS:dh>
187  $<TARGET_OBJECTS:dsa>
188  $<TARGET_OBJECTS:rsa>
189  $<TARGET_OBJECTS:ec>
190  $<TARGET_OBJECTS:ecdh>
191  $<TARGET_OBJECTS:ecdsa>
192  $<TARGET_OBJECTS:hmac>
193  $<TARGET_OBJECTS:cmac>
194  $<TARGET_OBJECTS:evp>
195  $<TARGET_OBJECTS:hkdf>
196  $<TARGET_OBJECTS:pem>
197  $<TARGET_OBJECTS:x509>
198  $<TARGET_OBJECTS:x509v3>
199  $<TARGET_OBJECTS:pkcs8>
200)
201
202if(NOT MSVC AND NOT ANDROID)
203  target_link_libraries(crypto pthread)
204endif()
205
206add_executable(
207  constant_time_test
208
209  constant_time_test.c
210
211  $<TARGET_OBJECTS:test_support>
212)
213
214target_link_libraries(constant_time_test crypto)
215
216add_executable(
217  thread_test
218
219  thread_test.c
220
221  $<TARGET_OBJECTS:test_support>
222)
223
224target_link_libraries(thread_test crypto)
225
226add_executable(
227  refcount_test
228
229  refcount_test.c
230)
231
232target_link_libraries(refcount_test crypto)
233
234perlasm(cpu-x86_64-asm.${ASM_EXT} cpu-x86_64-asm.pl)
235perlasm(cpu-x86-asm.${ASM_EXT} cpu-x86-asm.pl)
236