You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 16 KiB

Do a cursory conversion of a few tests to GTest. For now, this is the laziest conversion possible. The intent is to just get the build setup ready so that we can get everything working in our consumers. The intended end state is: - The standalone build produces three test targets, one per library: {crypto,ssl,decrepit}_tests. - Each FOO_test is made up of: FOO/**/*_test.cc crypto/test/gtest_main.cc test_support - generate_build_files.py emits variables crypto_test_sources and ssl_test_sources. These variables are populated with FindCFiles, looking for *_test.cc. - The consuming file assembles those variables into the two test targets (plus decrepit) from there. This avoids having generate_build_files.py emit actual build rules. - Our standalone builders, Chromium, and Android just run the top-level test targets using whatever GTest-based reporting story they have. In transition, we start by converting one of two tests in each library to populate the three test targets. Those are added to all_tests.json and all_tests.go hacked to handle them transparently. This keeps our standalone builder working. generate_build_files.py, to start with, populates the new source lists manually and subtracts them out of the old machinery. We emit both for the time being. When this change rolls in, we'll write all the build glue needed to build the GTest-based tests and add it to consumers' continuous builders. Next, we'll subsume a file-based test and get the consumers working with that. (I.e. make sure the GTest targets can depend on a data file.) Once that's all done, we'll be sure all this will work. At that point, we start subsuming the remaining tests into the GTest targets and, asynchronously, rewriting tests to use GTest properly rather than cursory conversion here. When all non-GTest tests are gone, the old generate_build_files.py hooks will be removed, consumers updated to not depend on them, and standalone builders converted to not rely on all_tests.go, which can then be removed. (Unless bits end up being needed as a malloc test driver. I'm thinking we'll want to do something with --gtest_filter.) As part of this CL, I've bumped the CMake requirements (for target_include_directories) and added a few suppressions for warnings that GTest doesn't pass. BUG=129 Change-Id: I881b26b07a8739cc0b52dbb51a30956908e1b71a Reviewed-on: https://boringssl-review.googlesource.com/13232 Reviewed-by: Adam Langley <agl@google.com>
7 years ago
Do a cursory conversion of a few tests to GTest. For now, this is the laziest conversion possible. The intent is to just get the build setup ready so that we can get everything working in our consumers. The intended end state is: - The standalone build produces three test targets, one per library: {crypto,ssl,decrepit}_tests. - Each FOO_test is made up of: FOO/**/*_test.cc crypto/test/gtest_main.cc test_support - generate_build_files.py emits variables crypto_test_sources and ssl_test_sources. These variables are populated with FindCFiles, looking for *_test.cc. - The consuming file assembles those variables into the two test targets (plus decrepit) from there. This avoids having generate_build_files.py emit actual build rules. - Our standalone builders, Chromium, and Android just run the top-level test targets using whatever GTest-based reporting story they have. In transition, we start by converting one of two tests in each library to populate the three test targets. Those are added to all_tests.json and all_tests.go hacked to handle them transparently. This keeps our standalone builder working. generate_build_files.py, to start with, populates the new source lists manually and subtracts them out of the old machinery. We emit both for the time being. When this change rolls in, we'll write all the build glue needed to build the GTest-based tests and add it to consumers' continuous builders. Next, we'll subsume a file-based test and get the consumers working with that. (I.e. make sure the GTest targets can depend on a data file.) Once that's all done, we'll be sure all this will work. At that point, we start subsuming the remaining tests into the GTest targets and, asynchronously, rewriting tests to use GTest properly rather than cursory conversion here. When all non-GTest tests are gone, the old generate_build_files.py hooks will be removed, consumers updated to not depend on them, and standalone builders converted to not rely on all_tests.go, which can then be removed. (Unless bits end up being needed as a malloc test driver. I'm thinking we'll want to do something with --gtest_filter.) As part of this CL, I've bumped the CMake requirements (for target_include_directories) and added a few suppressions for warnings that GTest doesn't pass. BUG=129 Change-Id: I881b26b07a8739cc0b52dbb51a30956908e1b71a Reviewed-on: https://boringssl-review.googlesource.com/13232 Reviewed-by: Adam Langley <agl@google.com>
7 years ago
Do a cursory conversion of a few tests to GTest. For now, this is the laziest conversion possible. The intent is to just get the build setup ready so that we can get everything working in our consumers. The intended end state is: - The standalone build produces three test targets, one per library: {crypto,ssl,decrepit}_tests. - Each FOO_test is made up of: FOO/**/*_test.cc crypto/test/gtest_main.cc test_support - generate_build_files.py emits variables crypto_test_sources and ssl_test_sources. These variables are populated with FindCFiles, looking for *_test.cc. - The consuming file assembles those variables into the two test targets (plus decrepit) from there. This avoids having generate_build_files.py emit actual build rules. - Our standalone builders, Chromium, and Android just run the top-level test targets using whatever GTest-based reporting story they have. In transition, we start by converting one of two tests in each library to populate the three test targets. Those are added to all_tests.json and all_tests.go hacked to handle them transparently. This keeps our standalone builder working. generate_build_files.py, to start with, populates the new source lists manually and subtracts them out of the old machinery. We emit both for the time being. When this change rolls in, we'll write all the build glue needed to build the GTest-based tests and add it to consumers' continuous builders. Next, we'll subsume a file-based test and get the consumers working with that. (I.e. make sure the GTest targets can depend on a data file.) Once that's all done, we'll be sure all this will work. At that point, we start subsuming the remaining tests into the GTest targets and, asynchronously, rewriting tests to use GTest properly rather than cursory conversion here. When all non-GTest tests are gone, the old generate_build_files.py hooks will be removed, consumers updated to not depend on them, and standalone builders converted to not rely on all_tests.go, which can then be removed. (Unless bits end up being needed as a malloc test driver. I'm thinking we'll want to do something with --gtest_filter.) As part of this CL, I've bumped the CMake requirements (for target_include_directories) and added a few suppressions for warnings that GTest doesn't pass. BUG=129 Change-Id: I881b26b07a8739cc0b52dbb51a30956908e1b71a Reviewed-on: https://boringssl-review.googlesource.com/13232 Reviewed-by: Adam Langley <agl@google.com>
7 years ago
Do a cursory conversion of a few tests to GTest. For now, this is the laziest conversion possible. The intent is to just get the build setup ready so that we can get everything working in our consumers. The intended end state is: - The standalone build produces three test targets, one per library: {crypto,ssl,decrepit}_tests. - Each FOO_test is made up of: FOO/**/*_test.cc crypto/test/gtest_main.cc test_support - generate_build_files.py emits variables crypto_test_sources and ssl_test_sources. These variables are populated with FindCFiles, looking for *_test.cc. - The consuming file assembles those variables into the two test targets (plus decrepit) from there. This avoids having generate_build_files.py emit actual build rules. - Our standalone builders, Chromium, and Android just run the top-level test targets using whatever GTest-based reporting story they have. In transition, we start by converting one of two tests in each library to populate the three test targets. Those are added to all_tests.json and all_tests.go hacked to handle them transparently. This keeps our standalone builder working. generate_build_files.py, to start with, populates the new source lists manually and subtracts them out of the old machinery. We emit both for the time being. When this change rolls in, we'll write all the build glue needed to build the GTest-based tests and add it to consumers' continuous builders. Next, we'll subsume a file-based test and get the consumers working with that. (I.e. make sure the GTest targets can depend on a data file.) Once that's all done, we'll be sure all this will work. At that point, we start subsuming the remaining tests into the GTest targets and, asynchronously, rewriting tests to use GTest properly rather than cursory conversion here. When all non-GTest tests are gone, the old generate_build_files.py hooks will be removed, consumers updated to not depend on them, and standalone builders converted to not rely on all_tests.go, which can then be removed. (Unless bits end up being needed as a malloc test driver. I'm thinking we'll want to do something with --gtest_filter.) As part of this CL, I've bumped the CMake requirements (for target_include_directories) and added a few suppressions for warnings that GTest doesn't pass. BUG=129 Change-Id: I881b26b07a8739cc0b52dbb51a30956908e1b71a Reviewed-on: https://boringssl-review.googlesource.com/13232 Reviewed-by: Adam Langley <agl@google.com>
7 years ago
Fix build when using Visual Studio 2015 Update 1. Many of the compatibility issues are described at https://msdn.microsoft.com/en-us/library/mt612856.aspx. The macros that suppressed warnings on a per-function basis no longer work in Update 1, so replace them with #pragmas. Update 1 warns when |size_t| arguments to |printf| are casted, so stop doing that casting. Unfortunately, this requires an ugly hack to continue working in MSVC 2013 as MSVC 2013 doesn't support "%zu". Finally, Update 1 has new warnings, some of which need to be suppressed. --- Updated by davidben to give up on suppressing warnings in crypto/x509 and crypto/x509v3 as those directories aren't changed much from upstream. In each of these cases, upstream opted just blindly initialize the variable, so do the same. Also switch C4265 to level 4, per Microsoft's recommendation and work around a bug in limits.h that happens to get fixed by Google include order style. (limits.h is sensitive to whether corecrt.h, pulled in by stddef.h and some other headers, is included before it. The reason it affected just one file is we often put the file's header first, which means base.h is pulling in stddef.h. Relying on this is ugly, but it's no worse than what everything else is doing and this doesn't seem worth making something as tame as limits.h so messy to use.) Change-Id: I02d1f935356899f424d3525d03eca401bfa3e6cd Reviewed-on: https://boringssl-review.googlesource.com/7480 Reviewed-by: David Benjamin <davidben@google.com>
8 years ago
Do a cursory conversion of a few tests to GTest. For now, this is the laziest conversion possible. The intent is to just get the build setup ready so that we can get everything working in our consumers. The intended end state is: - The standalone build produces three test targets, one per library: {crypto,ssl,decrepit}_tests. - Each FOO_test is made up of: FOO/**/*_test.cc crypto/test/gtest_main.cc test_support - generate_build_files.py emits variables crypto_test_sources and ssl_test_sources. These variables are populated with FindCFiles, looking for *_test.cc. - The consuming file assembles those variables into the two test targets (plus decrepit) from there. This avoids having generate_build_files.py emit actual build rules. - Our standalone builders, Chromium, and Android just run the top-level test targets using whatever GTest-based reporting story they have. In transition, we start by converting one of two tests in each library to populate the three test targets. Those are added to all_tests.json and all_tests.go hacked to handle them transparently. This keeps our standalone builder working. generate_build_files.py, to start with, populates the new source lists manually and subtracts them out of the old machinery. We emit both for the time being. When this change rolls in, we'll write all the build glue needed to build the GTest-based tests and add it to consumers' continuous builders. Next, we'll subsume a file-based test and get the consumers working with that. (I.e. make sure the GTest targets can depend on a data file.) Once that's all done, we'll be sure all this will work. At that point, we start subsuming the remaining tests into the GTest targets and, asynchronously, rewriting tests to use GTest properly rather than cursory conversion here. When all non-GTest tests are gone, the old generate_build_files.py hooks will be removed, consumers updated to not depend on them, and standalone builders converted to not rely on all_tests.go, which can then be removed. (Unless bits end up being needed as a malloc test driver. I'm thinking we'll want to do something with --gtest_filter.) As part of this CL, I've bumped the CMake requirements (for target_include_directories) and added a few suppressions for warnings that GTest doesn't pass. BUG=129 Change-Id: I881b26b07a8739cc0b52dbb51a30956908e1b71a Reviewed-on: https://boringssl-review.googlesource.com/13232 Reviewed-by: Adam Langley <agl@google.com>
7 years ago
Do a cursory conversion of a few tests to GTest. For now, this is the laziest conversion possible. The intent is to just get the build setup ready so that we can get everything working in our consumers. The intended end state is: - The standalone build produces three test targets, one per library: {crypto,ssl,decrepit}_tests. - Each FOO_test is made up of: FOO/**/*_test.cc crypto/test/gtest_main.cc test_support - generate_build_files.py emits variables crypto_test_sources and ssl_test_sources. These variables are populated with FindCFiles, looking for *_test.cc. - The consuming file assembles those variables into the two test targets (plus decrepit) from there. This avoids having generate_build_files.py emit actual build rules. - Our standalone builders, Chromium, and Android just run the top-level test targets using whatever GTest-based reporting story they have. In transition, we start by converting one of two tests in each library to populate the three test targets. Those are added to all_tests.json and all_tests.go hacked to handle them transparently. This keeps our standalone builder working. generate_build_files.py, to start with, populates the new source lists manually and subtracts them out of the old machinery. We emit both for the time being. When this change rolls in, we'll write all the build glue needed to build the GTest-based tests and add it to consumers' continuous builders. Next, we'll subsume a file-based test and get the consumers working with that. (I.e. make sure the GTest targets can depend on a data file.) Once that's all done, we'll be sure all this will work. At that point, we start subsuming the remaining tests into the GTest targets and, asynchronously, rewriting tests to use GTest properly rather than cursory conversion here. When all non-GTest tests are gone, the old generate_build_files.py hooks will be removed, consumers updated to not depend on them, and standalone builders converted to not rely on all_tests.go, which can then be removed. (Unless bits end up being needed as a malloc test driver. I'm thinking we'll want to do something with --gtest_filter.) As part of this CL, I've bumped the CMake requirements (for target_include_directories) and added a few suppressions for warnings that GTest doesn't pass. BUG=129 Change-Id: I881b26b07a8739cc0b52dbb51a30956908e1b71a Reviewed-on: https://boringssl-review.googlesource.com/13232 Reviewed-by: Adam Langley <agl@google.com>
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. cmake_minimum_required (VERSION 2.8.11)
  2. # Report AppleClang separately from Clang. Their version numbers are different.
  3. # https://cmake.org/cmake/help/v3.0/policy/CMP0025.html
  4. if(POLICY CMP0025)
  5. cmake_policy(SET CMP0025 NEW)
  6. endif()
  7. # Defer enabling C and CXX languages.
  8. project (BoringSSL NONE)
  9. if(WIN32)
  10. # On Windows, prefer cl over gcc if both are available. By default most of
  11. # the CMake generators prefer gcc, even on Windows.
  12. set(CMAKE_GENERATOR_CC cl)
  13. endif()
  14. include(sources.cmake)
  15. enable_language(C)
  16. enable_language(CXX)
  17. if(ANDROID)
  18. # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
  19. # found. However, ninja will still find them in $PATH if we just name them.
  20. if(NOT PERL_EXECUTABLE)
  21. set(PERL_EXECUTABLE "perl")
  22. endif()
  23. if(NOT GO_EXECUTABLE)
  24. set(GO_EXECUTABLE "go")
  25. endif()
  26. else()
  27. find_package(Perl REQUIRED)
  28. find_program(GO_EXECUTABLE go)
  29. endif()
  30. if (NOT GO_EXECUTABLE)
  31. message(FATAL_ERROR "Could not find Go")
  32. endif()
  33. if (BORINGSSL_ALLOW_CXX_RUNTIME)
  34. add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME)
  35. endif()
  36. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  37. set(CLANG 1)
  38. endif()
  39. if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
  40. # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
  41. # primarily on our normal Clang one.
  42. set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings")
  43. if(MSVC)
  44. # clang-cl sets different default warnings than clang. It also treats -Wall
  45. # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall.
  46. # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116
  47. set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900")
  48. # googletest suppresses warning C4996 via a pragma, but clang-cl does not
  49. # honor it. Suppress it here to compensate. See https://crbug.com/772117.
  50. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations")
  51. else()
  52. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -ggdb -fvisibility=hidden -fno-common")
  53. endif()
  54. if(CLANG)
  55. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
  56. else()
  57. # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
  58. # and declare that the code is trying to free a stack pointer.
  59. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object")
  60. endif()
  61. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
  62. NOT "6.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
  63. # Clang's -Wtautological-constant-compare is far too aggressive and does not
  64. # account for, say, wanting the same code to work on both 32-bit and 64-bit
  65. # platforms.
  66. #
  67. # Note "Clang" and "AppleClang" version differently, so we check for an
  68. # exact match on the COMPILER_ID. As of writing, the warning is not in any
  69. # release of AppleClang yet.
  70. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-tautological-constant-compare -Wtautological-constant-out-of-range-compare")
  71. endif()
  72. if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
  73. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
  74. endif()
  75. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
  76. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
  77. if(NOT MSVC)
  78. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  79. if(APPLE)
  80. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  81. endif()
  82. if(NOT BORINGSSL_ALLOW_CXX_RUNTIME)
  83. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
  84. endif()
  85. endif()
  86. # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
  87. # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
  88. # spelling for both and -Wmissing-declarations is some other warning.
  89. #
  90. # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
  91. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
  92. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
  93. if(CLANG)
  94. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
  95. endif()
  96. if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
  97. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
  98. endif()
  99. elseif(MSVC)
  100. set(MSVC_DISABLED_WARNINGS_LIST
  101. "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not
  102. # explicitly handled by a case label
  103. # Disable this because it flags even when there is a default.
  104. "C4100" # 'exarg' : unreferenced formal parameter
  105. "C4127" # conditional expression is constant
  106. "C4200" # nonstandard extension used : zero-sized array in
  107. # struct/union.
  108. "C4204" # nonstandard extension used: non-constant aggregate initializer
  109. "C4221" # nonstandard extension used : 'identifier' : cannot be
  110. # initialized using address of automatic variable
  111. "C4242" # 'function' : conversion from 'int' to 'uint8_t',
  112. # possible loss of data
  113. "C4244" # 'function' : conversion from 'int' to 'uint8_t',
  114. # possible loss of data
  115. "C4267" # conversion from 'size_t' to 'int', possible loss of data
  116. "C4371" # layout of class may have changed from a previous version of the
  117. # compiler due to better packing of member '...'
  118. "C4388" # signed/unsigned mismatch
  119. "C4296" # '>=' : expression is always true
  120. "C4350" # behavior change: 'std::_Wrap_alloc...'
  121. "C4365" # '=' : conversion from 'size_t' to 'int',
  122. # signed/unsigned mismatch
  123. "C4389" # '!=' : signed/unsigned mismatch
  124. "C4464" # relative include path contains '..'
  125. "C4510" # 'argument' : default constructor could not be generated
  126. "C4512" # 'argument' : assignment operator could not be generated
  127. "C4514" # 'function': unreferenced inline function has been removed
  128. "C4548" # expression before comma has no effect; expected expression with
  129. # side-effect" caused by FD_* macros.
  130. "C4610" # struct 'argument' can never be instantiated - user defined
  131. # constructor required.
  132. "C4623" # default constructor was implicitly defined as deleted
  133. "C4625" # copy constructor could not be generated because a base class
  134. # copy constructor is inaccessible or deleted
  135. "C4626" # assignment operator could not be generated because a base class
  136. # assignment operator is inaccessible or deleted
  137. "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with
  138. # '0' for 'directives'
  139. # Disable this because GTest uses it everywhere.
  140. "C4706" # assignment within conditional expression
  141. "C4710" # 'function': function not inlined
  142. "C4711" # function 'function' selected for inline expansion
  143. "C4800" # 'int' : forcing value to bool 'true' or 'false'
  144. # (performance warning)
  145. "C4820" # 'bytes' bytes padding added after construct 'member_name'
  146. "C5026" # move constructor was implicitly defined as deleted
  147. "C5027" # move assignment operator was implicitly defined as deleted
  148. )
  149. set(MSVC_LEVEL4_WARNINGS_LIST
  150. # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
  151. "C4265" # class has virtual functions, but destructor is not virtual
  152. )
  153. string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
  154. ${MSVC_DISABLED_WARNINGS_LIST})
  155. string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
  156. ${MSVC_LEVEL4_WARNINGS_LIST})
  157. set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  158. set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  159. endif()
  160. if(WIN32)
  161. add_definitions(-D_HAS_EXCEPTIONS=0)
  162. add_definitions(-DWIN32_LEAN_AND_MEAN)
  163. add_definitions(-DNOMINMAX)
  164. # Allow use of fopen.
  165. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  166. # VS 2017 and higher supports STL-only warning suppressions.
  167. add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
  168. endif()
  169. if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
  170. CLANG)
  171. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
  172. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
  173. endif()
  174. if(CMAKE_COMPILER_IS_GNUCXX)
  175. if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
  176. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
  177. else()
  178. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
  179. endif()
  180. endif()
  181. # pthread_rwlock_t requires a feature flag.
  182. if(NOT WIN32)
  183. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
  184. endif()
  185. if(FUZZ)
  186. if(NOT CLANG)
  187. message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
  188. endif()
  189. add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
  190. set(RUNNER_ARGS "-deterministic")
  191. if(NOT NO_FUZZER_MODE)
  192. add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
  193. set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
  194. endif()
  195. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
  196. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
  197. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  198. link_directories(.)
  199. endif()
  200. add_definitions(-DBORINGSSL_IMPLEMENTATION)
  201. if (BUILD_SHARED_LIBS)
  202. add_definitions(-DBORINGSSL_SHARED_LIBRARY)
  203. # Enable position-independent code globally. This is needed because
  204. # some library targets are OBJECT libraries.
  205. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  206. endif()
  207. if (MSAN)
  208. if(NOT CLANG)
  209. message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
  210. endif()
  211. if (ASAN)
  212. message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
  213. endif()
  214. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
  215. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
  216. set(OPENSSL_NO_ASM "1")
  217. endif()
  218. if (ASAN)
  219. if(NOT CLANG)
  220. message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
  221. endif()
  222. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  223. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  224. set(OPENSSL_NO_ASM "1")
  225. endif()
  226. if(CFI)
  227. if(NOT CLANG)
  228. message(FATAL_ERROR "Cannot enable CFI unless using Clang")
  229. endif()
  230. # TODO(crbug.com/785442): Remove -fsanitize-cfi-icall-generalize-pointers.
  231. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
  232. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
  233. # We use Chromium's copy of clang, which requires -fuse-ld=lld if building
  234. # with -flto. That, in turn, can't handle -ggdb.
  235. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
  236. string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  237. string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  238. # -flto causes object files to contain LLVM bitcode. Mixing those with
  239. # assembly output in the same static library breaks the linker.
  240. set(OPENSSL_NO_ASM "1")
  241. endif()
  242. if (GCOV)
  243. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  244. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  245. endif()
  246. if(FIPS)
  247. add_definitions(-DBORINGSSL_FIPS)
  248. if(FIPS_BREAK_TEST)
  249. add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
  250. endif()
  251. # Delocate does not work for ASan and MSan builds.
  252. if(NOT ASAN AND NOT MSAN)
  253. set(FIPS_DELOCATE "1")
  254. endif()
  255. endif()
  256. # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
  257. # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
  258. # alone, and expects all architecture-specific logic to be conditioned within
  259. # the source files rather than the build. This does not work for our assembly
  260. # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
  261. # builds.
  262. if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
  263. list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
  264. if (NOT ${NUM_ARCHES} EQUAL 1)
  265. message(FATAL_ERROR "Universal binaries not supported.")
  266. endif()
  267. list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
  268. endif()
  269. if (OPENSSL_NO_ASM)
  270. add_definitions(-DOPENSSL_NO_ASM)
  271. set(ARCH "generic")
  272. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  273. set(ARCH "x86_64")
  274. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  275. set(ARCH "x86_64")
  276. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  277. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
  278. if (CMAKE_CL_64)
  279. set(ARCH "x86_64")
  280. else()
  281. set(ARCH "x86")
  282. endif()
  283. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  284. set(ARCH "x86")
  285. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  286. set(ARCH "x86")
  287. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  288. set(ARCH "x86")
  289. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  290. set(ARCH "aarch64")
  291. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
  292. set(ARCH "aarch64")
  293. elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
  294. set(ARCH "arm")
  295. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
  296. # Just to avoid the “unknown processor” error.
  297. set(ARCH "generic")
  298. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
  299. set(ARCH "ppc64le")
  300. else()
  301. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  302. endif()
  303. if (ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm")
  304. # The third-party Android-NDK CMake files somehow fail to set the -march flag
  305. # for assembly files. Without this flag, the compiler believes that it's
  306. # building for ARMv5.
  307. set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}")
  308. endif()
  309. if (${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
  310. # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
  311. # but clang defaults to 64-bit builds on OS X unless otherwise told.
  312. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
  313. set(ARCH "x86_64")
  314. endif()
  315. # Add minimal googletest targets. The provided one has many side-effects, and
  316. # googletest has a very straightforward build.
  317. add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc)
  318. target_include_directories(boringssl_gtest PRIVATE third_party/googletest)
  319. include_directories(third_party/googletest/include)
  320. # Declare a dummy target to build all unit tests. Test targets should inject
  321. # themselves as dependencies next to the target definition.
  322. add_custom_target(all_tests)
  323. add_custom_command(
  324. OUTPUT crypto_test_data.cc
  325. COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} >
  326. ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc
  327. DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA}
  328. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  329. add_library(crypto_test_data OBJECT crypto_test_data.cc)
  330. add_subdirectory(crypto)
  331. add_subdirectory(third_party/fiat)
  332. add_subdirectory(ssl)
  333. add_subdirectory(ssl/test)
  334. add_subdirectory(fipstools)
  335. add_subdirectory(tool)
  336. add_subdirectory(decrepit)
  337. if(FUZZ)
  338. if(LIBFUZZER_FROM_DEPS)
  339. file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
  340. add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
  341. # libFuzzer does not pass our aggressive warnings. It also must be built
  342. # without -fsanitize-coverage options or clang crashes.
  343. set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0")
  344. endif()
  345. add_subdirectory(fuzz)
  346. endif()
  347. if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
  348. # USES_TERMINAL is only available in CMake 3.2 or later.
  349. set(MAYBE_USES_TERMINAL USES_TERMINAL)
  350. endif()
  351. add_custom_target(
  352. run_tests
  353. COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
  354. ${CMAKE_BINARY_DIR}
  355. COMMAND cd ssl/test/runner &&
  356. ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
  357. ${RUNNER_ARGS}
  358. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  359. DEPENDS all_tests bssl_shim
  360. ${MAYBE_USES_TERMINAL})