blob: ef8c2d4087e20134533228d062c46edd08c6caea [file] [log] [blame]
Kenny Rootb8494592015-09-25 02:29:14 +00001include_directories(../include)
Adam Langleyd9e397b2015-01-22 14:27:53 -08002
Robert Sloan572a4e22017-04-17 10:52:19 -07003if(UNIX)
Adam Langleyd9e397b2015-01-22 14:27:53 -08004 if (${ARCH} STREQUAL "aarch64")
5 # The "armx" Perl scripts look for "64" in the style argument
6 # in order to decide whether to generate 32- or 64-bit asm.
Robert Sloan572a4e22017-04-17 10:52:19 -07007 if (APPLE)
8 set(PERLASM_STYLE ios64)
9 else()
10 set(PERLASM_STYLE linux64)
11 endif()
Adam Langleye9ada862015-05-11 17:20:37 -070012 elseif (${ARCH} STREQUAL "arm")
Robert Sloan572a4e22017-04-17 10:52:19 -070013 if (APPLE)
14 set(PERLASM_STYLE ios32)
15 else()
16 set(PERLASM_STYLE linux32)
17 endif()
Steven Valdezbb1ceac2016-10-07 10:34:51 -040018 elseif (${ARCH} STREQUAL "ppc64le")
19 set(PERLASM_STYLE ppc64le)
Adam Langleyd9e397b2015-01-22 14:27:53 -080020 else()
Robert Sloan572a4e22017-04-17 10:52:19 -070021 if (${ARCH} STREQUAL "x86")
22 set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
23 endif()
24 if (APPLE)
25 set(PERLASM_STYLE macosx)
26 else()
27 set(PERLASM_STYLE elf)
28 endif()
Adam Langleyd9e397b2015-01-22 14:27:53 -080029 endif()
30 set(ASM_EXT S)
31 enable_language(ASM)
David Benjamin4969cc92016-04-22 15:02:23 -040032 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
Robert Sloan572a4e22017-04-17 10:52:19 -070033
34 # CMake does not add -isysroot and -arch flags to assembly.
35 if (APPLE)
36 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
37 foreach(arch ${CMAKE_OSX_ARCHITECTURES})
38 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
39 endforeach()
40 endif()
Adam Langleyd9e397b2015-01-22 14:27:53 -080041else()
42 if (CMAKE_CL_64)
43 message("Using nasm")
44 set(PERLASM_STYLE nasm)
45 else()
46 message("Using win32n")
47 set(PERLASM_STYLE win32n)
Adam Langleye9ada862015-05-11 17:20:37 -070048 set(PERLASM_FLAGS "-DOPENSSL_IA32_SSE2")
Adam Langleyd9e397b2015-01-22 14:27:53 -080049 endif()
50
51 # On Windows, we use the NASM output, specifically built with Yasm.
52 set(ASM_EXT asm)
53 enable_language(ASM_NASM)
54endif()
55
56function(perlasm dest src)
57 add_custom_command(
58 OUTPUT ${dest}
David Benjaminc895d6b2016-08-11 13:26:41 -040059 COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} ${dest}
Adam Langleyd9e397b2015-01-22 14:27:53 -080060 DEPENDS
61 ${src}
Adam Langleye9ada862015-05-11 17:20:37 -070062 ${PROJECT_SOURCE_DIR}/crypto/perlasm/arm-xlate.pl
Steven Valdezbb1ceac2016-10-07 10:34:51 -040063 ${PROJECT_SOURCE_DIR}/crypto/perlasm/ppc-xlate.pl
Adam Langleyd9e397b2015-01-22 14:27:53 -080064 ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl
65 ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86asm.pl
66 ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86gas.pl
67 ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86masm.pl
68 ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86nasm.pl
69 WORKING_DIRECTORY .
70 )
71endfunction()
72
Adam Langleyd9e397b2015-01-22 14:27:53 -080073# Level 0.1 - depends on nothing outside this set.
74add_subdirectory(stack)
75add_subdirectory(lhash)
76add_subdirectory(err)
77add_subdirectory(buf)
78add_subdirectory(base64)
79add_subdirectory(bytestring)
Steven Valdez909b19f2016-11-21 15:35:44 -050080add_subdirectory(pool)
Adam Langleyd9e397b2015-01-22 14:27:53 -080081
82# Level 0.2 - depends on nothing but itself
Adam Langleyd9e397b2015-01-22 14:27:53 -080083add_subdirectory(modes)
Adam Langleyd9e397b2015-01-22 14:27:53 -080084add_subdirectory(des)
85add_subdirectory(rc4)
86add_subdirectory(conf)
87add_subdirectory(chacha)
88add_subdirectory(poly1305)
Adam Langley4139edb2016-01-13 15:00:54 -080089add_subdirectory(curve25519)
Adam Langleyd9e397b2015-01-22 14:27:53 -080090
91# Level 1, depends only on 0.*
Robert Sloan572a4e22017-04-17 10:52:19 -070092add_subdirectory(digest_extra)
Adam Langleyd9e397b2015-01-22 14:27:53 -080093add_subdirectory(cipher)
94add_subdirectory(rand)
95add_subdirectory(bio)
96add_subdirectory(bn)
97add_subdirectory(obj)
98add_subdirectory(asn1)
99
100# Level 2
101add_subdirectory(engine)
102add_subdirectory(dh)
103add_subdirectory(dsa)
104add_subdirectory(rsa)
105add_subdirectory(ec)
106add_subdirectory(ecdh)
107add_subdirectory(ecdsa)
Robert Sloan572a4e22017-04-17 10:52:19 -0700108add_subdirectory(hmac_extra)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800109
110# Level 3
Adam Langleye9ada862015-05-11 17:20:37 -0700111add_subdirectory(cmac)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800112add_subdirectory(evp)
113add_subdirectory(hkdf)
114add_subdirectory(pem)
115add_subdirectory(x509)
116add_subdirectory(x509v3)
117
118# Level 4
119add_subdirectory(pkcs8)
120
Adam Langleye9ada862015-05-11 17:20:37 -0700121# Test support code
122add_subdirectory(test)
123
Robert Sloan572a4e22017-04-17 10:52:19 -0700124add_subdirectory(fipsmodule)
125
Adam Langleyd9e397b2015-01-22 14:27:53 -0800126add_library(
Robert Sloan572a4e22017-04-17 10:52:19 -0700127 crypto_base
128
129 OBJECT
Adam Langleyd9e397b2015-01-22 14:27:53 -0800130
David Benjamin4969cc92016-04-22 15:02:23 -0400131 cpu-aarch64-linux.c
132 cpu-arm.c
133 cpu-arm-linux.c
134 cpu-intel.c
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400135 cpu-ppc64le.c
Adam Langleyd9e397b2015-01-22 14:27:53 -0800136 crypto.c
Adam Langleyf4e42722015-06-04 17:45:09 -0700137 ex_data.c
Adam Langleyd9e397b2015-01-22 14:27:53 -0800138 mem.c
Adam Langleyf4e42722015-06-04 17:45:09 -0700139 refcount_c11.c
140 refcount_lock.c
Adam Langleyd9e397b2015-01-22 14:27:53 -0800141 thread.c
Adam Langleye9ada862015-05-11 17:20:37 -0700142 thread_none.c
143 thread_pthread.c
144 thread_win.c
Robert Sloan572a4e22017-04-17 10:52:19 -0700145)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800146
Robert Sloan572a4e22017-04-17 10:52:19 -0700147if(FIPS)
148 SET_SOURCE_FILES_PROPERTIES(fipsmodule/bcm.o PROPERTIES EXTERNAL_OBJECT true)
149 SET_SOURCE_FILES_PROPERTIES(fipsmodule/bcm.o PROPERTIES GENERATED true)
150
151 set(
152 CRYPTO_FIPS_OBJECTS
153
154 fipsmodule/bcm.o
155 )
156endif()
157
158add_library(
159 crypto
160
161 $<TARGET_OBJECTS:crypto_base>
Adam Langleyd9e397b2015-01-22 14:27:53 -0800162 $<TARGET_OBJECTS:stack>
163 $<TARGET_OBJECTS:lhash>
164 $<TARGET_OBJECTS:err>
165 $<TARGET_OBJECTS:base64>
166 $<TARGET_OBJECTS:bytestring>
Steven Valdez909b19f2016-11-21 15:35:44 -0500167 $<TARGET_OBJECTS:pool>
Robert Sloan572a4e22017-04-17 10:52:19 -0700168 $<TARGET_OBJECTS:fipsmodule>
169 $<TARGET_OBJECTS:digest_extra>
Adam Langleyd9e397b2015-01-22 14:27:53 -0800170 $<TARGET_OBJECTS:cipher>
171 $<TARGET_OBJECTS:modes>
Adam Langleyd9e397b2015-01-22 14:27:53 -0800172 $<TARGET_OBJECTS:des>
173 $<TARGET_OBJECTS:rc4>
174 $<TARGET_OBJECTS:conf>
175 $<TARGET_OBJECTS:chacha>
176 $<TARGET_OBJECTS:poly1305>
Adam Langley4139edb2016-01-13 15:00:54 -0800177 $<TARGET_OBJECTS:curve25519>
Adam Langleyd9e397b2015-01-22 14:27:53 -0800178 $<TARGET_OBJECTS:buf>
179 $<TARGET_OBJECTS:bn>
180 $<TARGET_OBJECTS:bio>
181 $<TARGET_OBJECTS:rand>
182 $<TARGET_OBJECTS:obj>
183 $<TARGET_OBJECTS:asn1>
184 $<TARGET_OBJECTS:engine>
185 $<TARGET_OBJECTS:dh>
186 $<TARGET_OBJECTS:dsa>
187 $<TARGET_OBJECTS:rsa>
188 $<TARGET_OBJECTS:ec>
189 $<TARGET_OBJECTS:ecdh>
190 $<TARGET_OBJECTS:ecdsa>
Adam Langleye9ada862015-05-11 17:20:37 -0700191 $<TARGET_OBJECTS:cmac>
Adam Langleyd9e397b2015-01-22 14:27:53 -0800192 $<TARGET_OBJECTS:evp>
193 $<TARGET_OBJECTS:hkdf>
194 $<TARGET_OBJECTS:pem>
195 $<TARGET_OBJECTS:x509>
196 $<TARGET_OBJECTS:x509v3>
David Benjamin4969cc92016-04-22 15:02:23 -0400197 $<TARGET_OBJECTS:pkcs8_lib>
Robert Sloan572a4e22017-04-17 10:52:19 -0700198
199 ${CRYPTO_FIPS_OBJECTS}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800200)
201
Robert Sloan572a4e22017-04-17 10:52:19 -0700202if(FIPS)
203 add_dependencies(crypto bcm_o_target)
204endif()
205
206SET_TARGET_PROPERTIES(crypto PROPERTIES LINKER_LANGUAGE C)
207
Adam Langleye9ada862015-05-11 17:20:37 -0700208if(NOT MSVC AND NOT ANDROID)
209 target_link_libraries(crypto pthread)
210endif()
211
Adam Langleyd9e397b2015-01-22 14:27:53 -0800212add_executable(
Adam Langleye9ada862015-05-11 17:20:37 -0700213 thread_test
214
215 thread_test.c
Adam Langleyf4e42722015-06-04 17:45:09 -0700216
217 $<TARGET_OBJECTS:test_support>
Adam Langleye9ada862015-05-11 17:20:37 -0700218)
219
220target_link_libraries(thread_test crypto)
Kenny Roote99801b2015-11-06 15:31:15 -0800221add_dependencies(all_tests thread_test)
Adam Langleye9ada862015-05-11 17:20:37 -0700222
Adam Langleyf4e42722015-06-04 17:45:09 -0700223add_executable(
224 refcount_test
225
Robert Sloan69939df2017-01-09 10:53:07 -0800226 refcount_test.cc
Adam Langleyf4e42722015-06-04 17:45:09 -0700227)
228
229target_link_libraries(refcount_test crypto)
Kenny Roote99801b2015-11-06 15:31:15 -0800230add_dependencies(all_tests refcount_test)
David Benjaminf31229b2017-01-25 14:08:15 -0500231
232# TODO(davidben): Convert the remaining tests to GTest.
233add_executable(
234 crypto_test
235
Robert Sloan8ecb7cd2017-03-21 09:39:01 -0700236 asn1/asn1_test.cc
Robert Sloan572a4e22017-04-17 10:52:19 -0700237 base64/base64_test.cc
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700238 bio/bio_test.cc
Robert Sloan572a4e22017-04-17 10:52:19 -0700239 bytestring/bytestring_test.cc
Robert Sloana94fe052017-02-21 08:49:28 -0800240 chacha/chacha_test.cc
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700241 constant_time_test.cc
Robert Sloan7d422bc2017-03-06 10:04:29 -0800242 curve25519/x25519_test.cc
David Benjaminf31229b2017-01-25 14:08:15 -0500243 dh/dh_test.cc
244 dsa/dsa_test.cc
Robert Sloana94fe052017-02-21 08:49:28 -0800245 ec/ec_test.cc
Robert Sloan5d625782017-02-13 09:55:39 -0800246 err/err_test.cc
Robert Sloan7d422bc2017-03-06 10:04:29 -0800247 evp/evp_extra_test.cc
Robert Sloan572a4e22017-04-17 10:52:19 -0700248 rand/ctrdrbg_test.cc
Robert Sloana94fe052017-02-21 08:49:28 -0800249 rsa/rsa_test.cc
David Benjaminf31229b2017-01-25 14:08:15 -0500250
251 $<TARGET_OBJECTS:gtest_main>
252 $<TARGET_OBJECTS:test_support>
253)
254
255target_link_libraries(crypto_test crypto gtest)
Robert Sloan6d0d00e2017-03-27 07:13:07 -0700256if (WIN32)
257 target_link_libraries(crypto_test ws2_32)
258endif()
David Benjaminf31229b2017-01-25 14:08:15 -0500259add_dependencies(all_tests crypto_test)