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  elseif (${ARCH} STREQUAL "ppc64le")
21    set(PERLASM_STYLE ppc64le)
22  else()
23    set(PERLASM_STYLE elf)
24  endif()
25  set(ASM_EXT S)
26  enable_language(ASM)
27  set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
28else()
29  if (CMAKE_CL_64)
30    message("Using nasm")
31    set(PERLASM_STYLE nasm)
32  else()
33    message("Using win32n")
34    set(PERLASM_STYLE win32n)
35    set(PERLASM_FLAGS "-DOPENSSL_IA32_SSE2")
36  endif()
37
38  # On Windows, we use the NASM output, specifically built with Yasm.
39  set(ASM_EXT asm)
40  enable_language(ASM_NASM)
41endif()
42
43function(perlasm dest src)
44  add_custom_command(
45    OUTPUT ${dest}
46    COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} ${dest}
47    DEPENDS
48    ${src}
49    ${PROJECT_SOURCE_DIR}/crypto/perlasm/arm-xlate.pl
50    ${PROJECT_SOURCE_DIR}/crypto/perlasm/ppc-xlate.pl
51    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl
52    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86asm.pl
53    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86gas.pl
54    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86masm.pl
55    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86nasm.pl
56    WORKING_DIRECTORY .
57  )
58endfunction()
59
60# Level 0.1 - depends on nothing outside this set.
61add_subdirectory(stack)
62add_subdirectory(lhash)
63add_subdirectory(err)
64add_subdirectory(buf)
65add_subdirectory(base64)
66add_subdirectory(bytestring)
67add_subdirectory(pool)
68
69# Level 0.2 - depends on nothing but itself
70add_subdirectory(sha)
71add_subdirectory(md4)
72add_subdirectory(md5)
73add_subdirectory(modes)
74add_subdirectory(aes)
75add_subdirectory(des)
76add_subdirectory(rc4)
77add_subdirectory(conf)
78add_subdirectory(chacha)
79add_subdirectory(poly1305)
80add_subdirectory(curve25519)
81
82# Level 1, depends only on 0.*
83add_subdirectory(digest)
84add_subdirectory(cipher)
85add_subdirectory(rand)
86add_subdirectory(bio)
87add_subdirectory(bn)
88add_subdirectory(obj)
89add_subdirectory(asn1)
90
91# Level 2
92add_subdirectory(engine)
93add_subdirectory(dh)
94add_subdirectory(dsa)
95add_subdirectory(rsa)
96add_subdirectory(ec)
97add_subdirectory(ecdh)
98add_subdirectory(ecdsa)
99add_subdirectory(hmac)
100
101# Level 3
102add_subdirectory(cmac)
103add_subdirectory(evp)
104add_subdirectory(hkdf)
105add_subdirectory(pem)
106add_subdirectory(x509)
107add_subdirectory(x509v3)
108
109# Level 4
110add_subdirectory(pkcs8)
111
112# Test support code
113add_subdirectory(test)
114
115add_library(
116  crypto
117
118  cpu-aarch64-linux.c
119  cpu-arm.c
120  cpu-arm-linux.c
121  cpu-intel.c
122  cpu-ppc64le.c
123  crypto.c
124  ex_data.c
125  mem.c
126  refcount_c11.c
127  refcount_lock.c
128  thread.c
129  thread_none.c
130  thread_pthread.c
131  thread_win.c
132
133  $<TARGET_OBJECTS:stack>
134  $<TARGET_OBJECTS:lhash>
135  $<TARGET_OBJECTS:err>
136  $<TARGET_OBJECTS:base64>
137  $<TARGET_OBJECTS:bytestring>
138  $<TARGET_OBJECTS:pool>
139  $<TARGET_OBJECTS:sha>
140  $<TARGET_OBJECTS:md4>
141  $<TARGET_OBJECTS:md5>
142  $<TARGET_OBJECTS:digest>
143  $<TARGET_OBJECTS:cipher>
144  $<TARGET_OBJECTS:modes>
145  $<TARGET_OBJECTS:aes>
146  $<TARGET_OBJECTS:des>
147  $<TARGET_OBJECTS:rc4>
148  $<TARGET_OBJECTS:conf>
149  $<TARGET_OBJECTS:chacha>
150  $<TARGET_OBJECTS:poly1305>
151  $<TARGET_OBJECTS:curve25519>
152  $<TARGET_OBJECTS:buf>
153  $<TARGET_OBJECTS:bn>
154  $<TARGET_OBJECTS:bio>
155  $<TARGET_OBJECTS:rand>
156  $<TARGET_OBJECTS:obj>
157  $<TARGET_OBJECTS:asn1>
158  $<TARGET_OBJECTS:engine>
159  $<TARGET_OBJECTS:dh>
160  $<TARGET_OBJECTS:dsa>
161  $<TARGET_OBJECTS:rsa>
162  $<TARGET_OBJECTS:ec>
163  $<TARGET_OBJECTS:ecdh>
164  $<TARGET_OBJECTS:ecdsa>
165  $<TARGET_OBJECTS:hmac>
166  $<TARGET_OBJECTS:cmac>
167  $<TARGET_OBJECTS:evp>
168  $<TARGET_OBJECTS:hkdf>
169  $<TARGET_OBJECTS:pem>
170  $<TARGET_OBJECTS:x509>
171  $<TARGET_OBJECTS:x509v3>
172  $<TARGET_OBJECTS:pkcs8_lib>
173)
174
175if(NOT MSVC AND NOT ANDROID)
176  target_link_libraries(crypto pthread)
177endif()
178
179add_executable(
180  thread_test
181
182  thread_test.c
183
184  $<TARGET_OBJECTS:test_support>
185)
186
187target_link_libraries(thread_test crypto)
188add_dependencies(all_tests thread_test)
189
190add_executable(
191  refcount_test
192
193  refcount_test.cc
194)
195
196target_link_libraries(refcount_test crypto)
197add_dependencies(all_tests refcount_test)
198
199# TODO(davidben): Convert the remaining tests to GTest.
200add_executable(
201  crypto_test
202
203  asn1/asn1_test.cc
204  bio/bio_test.cc
205  chacha/chacha_test.cc
206  constant_time_test.cc
207  curve25519/x25519_test.cc
208  dh/dh_test.cc
209  dsa/dsa_test.cc
210  ec/ec_test.cc
211  err/err_test.cc
212  evp/evp_extra_test.cc
213  rsa/rsa_test.cc
214
215  $<TARGET_OBJECTS:gtest_main>
216  $<TARGET_OBJECTS:test_support>
217)
218
219target_link_libraries(crypto_test crypto gtest)
220if (WIN32)
221  target_link_libraries(crypto_test ws2_32)
222endif()
223add_dependencies(all_tests crypto_test)
224