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 24 KiB

Add a CFI tester to CHECK_ABI. This uses the x86 trap flag and libunwind to test CFI works at each instruction. For now, it just uses the system one out of pkg-config and disables unwind tests if unavailable. We'll probably want to stick a copy into //third_party and perhaps try the LLVM one later. This tester caught two bugs in P-256 CFI annotations already: I47b5f9798b3bcee1748e537b21c173d312a14b42 and I9f576d868850312d6c14d1386f8fbfa85021b347 An earlier design used PTRACE_SINGLESTEP with libunwind's remote unwinding features. ptrace is a mess around stop signals (see group-stop discussion in ptrace(2)) and this is 10x faster, so I went with it. The question of which is more future-proof is complex: - There are two libunwinds with the same API, https://www.nongnu.org/libunwind/ and LLVM's. This currently uses the system nongnu.org for convenience. In future, LLVM's should be easier to bundle (less complex build) and appears to even support Windows, but I haven't tested this. Moreover, setting the trap flag keeps the test single-process, which is less complex on Windows. That suggests the trap flag design and switching to LLVM later. However... - Not all architectures have a trap flag settable by userspace. As far as I can tell, ARMv8's PSTATE.SS can only be set from the kernel. If we stick with nongnu.org libunwind, we can use PTRACE_SINGLESTEP and remote unwinding. Or we implement it for LLVM. Another thought is for the ptracer to bounce SIGTRAP back into the process, to share the local unwinding code. - ARMv7 has no trap flag at all and PTRACE_SINGLESTEP fails. Debuggers single-step by injecting breakpoints instead. However, ARMv8's trap flag seems to work in both AArch32 and AArch64 modes, so we may be able to condition it on a 64-bit kernel. Sadly, neither strategy works with Intel SDE. Adding flags to cpucap vectors as we do with ARM would help, but it would not emulate CPUs newer than the host CPU. For now, I've just had SDE tests disable these. Annoyingly, CMake does not allow object libraries to have dependencies, so make test_support a proper static library. Rename the target to test_support_lib to avoid https://gitlab.kitware.com/cmake/cmake/issues/17785 Update-Note: This adds a new optional test dependency, but it's disabled by default (define BORINGSSL_HAVE_LIBUNWIND), so consumers do not need to do anything. We'll probably want to adjust this in the future. Bug: 181 Change-Id: I817263d7907aff0904a9cee83f8b26747262cc0c Reviewed-on: https://boringssl-review.googlesource.com/c/33966 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
5 years ago
Add a CFI tester to CHECK_ABI. This uses the x86 trap flag and libunwind to test CFI works at each instruction. For now, it just uses the system one out of pkg-config and disables unwind tests if unavailable. We'll probably want to stick a copy into //third_party and perhaps try the LLVM one later. This tester caught two bugs in P-256 CFI annotations already: I47b5f9798b3bcee1748e537b21c173d312a14b42 and I9f576d868850312d6c14d1386f8fbfa85021b347 An earlier design used PTRACE_SINGLESTEP with libunwind's remote unwinding features. ptrace is a mess around stop signals (see group-stop discussion in ptrace(2)) and this is 10x faster, so I went with it. The question of which is more future-proof is complex: - There are two libunwinds with the same API, https://www.nongnu.org/libunwind/ and LLVM's. This currently uses the system nongnu.org for convenience. In future, LLVM's should be easier to bundle (less complex build) and appears to even support Windows, but I haven't tested this. Moreover, setting the trap flag keeps the test single-process, which is less complex on Windows. That suggests the trap flag design and switching to LLVM later. However... - Not all architectures have a trap flag settable by userspace. As far as I can tell, ARMv8's PSTATE.SS can only be set from the kernel. If we stick with nongnu.org libunwind, we can use PTRACE_SINGLESTEP and remote unwinding. Or we implement it for LLVM. Another thought is for the ptracer to bounce SIGTRAP back into the process, to share the local unwinding code. - ARMv7 has no trap flag at all and PTRACE_SINGLESTEP fails. Debuggers single-step by injecting breakpoints instead. However, ARMv8's trap flag seems to work in both AArch32 and AArch64 modes, so we may be able to condition it on a 64-bit kernel. Sadly, neither strategy works with Intel SDE. Adding flags to cpucap vectors as we do with ARM would help, but it would not emulate CPUs newer than the host CPU. For now, I've just had SDE tests disable these. Annoyingly, CMake does not allow object libraries to have dependencies, so make test_support a proper static library. Rename the target to test_support_lib to avoid https://gitlab.kitware.com/cmake/cmake/issues/17785 Update-Note: This adds a new optional test dependency, but it's disabled by default (define BORINGSSL_HAVE_LIBUNWIND), so consumers do not need to do anything. We'll probably want to adjust this in the future. Bug: 181 Change-Id: I817263d7907aff0904a9cee83f8b26747262cc0c Reviewed-on: https://boringssl-review.googlesource.com/c/33966 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
5 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
Add start of infrastructure for checking constant-time properties. Valgrind's checking of uninitialised memory behaves very much like a check for constant-time code: branches and memory indexes based on uninitialised memory trigger warnings. Therefore, if we can tell Valgrind that some secret is “uninitialised”, it'll give us a warning if we do something non-constant-time with it. This was the idea behind https://github.com/agl/ctgrind. But tricks like that are no longer needed because Valgrind now comes with support for marking regions of memory as defined or not. Therefore we can use that API to check constant-time code. This CL defines |CONSTTIME_SECRET| and |CONSTTIME_DECLASSIFY|, which are no-ops unless the code is built with |BORINGSSL_CONSTANT_TIME_VALIDATION| defined, which it isn't by default. So this CL is a no-op itself so far. But it does show that a couple of bits of constant-time time are, in fact, constant-time—seemingly even when compiled with optimisations, which is nice. The annotations in the RSA code are a) probably not marking all the secrets as secret, and b) triggers warnings that are a little interesting: The anti-glitch check calls |BN_mod_exp_mont| which checks that the input is less than the modulus. Of course, it is because the input is the RSA plaintext that we just decrypted, but the plaintext is supposed to be secret and so branching based on its contents isn't allows by Valgrind. The answer isn't totally clear, but I've run out of time on this for now. Change-Id: I1608ed0b22d201e97595fafe46127159e02d5b1b Reviewed-on: https://boringssl-review.googlesource.com/c/33504 Reviewed-by: Adam Langley <agl@google.com> Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: Adam Langley <agl@google.com>
5 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
Update tools. Unfortunately, this requires partially reverting https://boringssl-review.googlesource.com/31324. This is a mess. While clang proper includes a fuzzer driver, Chromium doesn't use it. Chromium builds exclusively with fuzzer-no-link and links to its own copy of the fuzzer runtime[1]. As of [2], Chromium's clang (which we use on bots) no longer includes the driver, so we must mimic them. However, Chromium's setup is somewhat questionable because fuzzer-no-link pulls in libclang_rt.fuzzer_no_main which still includes most of libclang_rt.fuzzer, just not the one main function[3]. It appears Chromium is actually linking two copies of libclang_rt.fuzzer_no_main. Hopefully this mostly works out as Chromium's clang and libFuzzer should be relatively aligned, but it's not a good assumption for our build, which can take other Clangs too. Thus, if you pass -DFUZZ=1 as-is, we will assume you are using a "normal" Clang with all its relevant runtimes intact. If, however, you are using Chromium clang, you must drop the matching libFuzzer where the bots expected it and build with -DLIBFUZZER_FROM_DEPS=1. This involves no changes to the bots because we never actually unwound all the LIBFUZZER_FROM_DEPS bits before. [1] https://cs.chromium.org/chromium/src/testing/libfuzzer/BUILD.gn?rcl=d21c49585f262e851e2984f96f52905782706325&l=14 [2] https://chromium.googlesource.com/chromium/src/+/c79bf2ea4cf65431dccb57cb2a44528c284645a1 [3] https://github.com/llvm-mirror/compiler-rt/blob/8ebc3668b07fc5cca6010265cd4795443f1c1bea/lib/fuzzer/CMakeLists.txt#L93-L107 https://github.com/llvm-mirror/compiler-rt/blob/8ebc3668b07fc5cca6010265cd4795443f1c1bea/lib/fuzzer/FuzzerMain.cpp Change-Id: I946b3c821c3d7e6def7e07f1381f58241611ba3d Reviewed-on: https://boringssl-review.googlesource.com/c/34184 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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. # This is a dummy target which all other targets depend on (manually - see other
  18. # CMakeLists.txt files). This gives us a hook to add any targets which need to
  19. # run before all other targets.
  20. add_custom_target(global_target)
  21. if(ANDROID)
  22. # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
  23. # found. However, ninja will still find them in $PATH if we just name them.
  24. if(NOT PERL_EXECUTABLE)
  25. set(PERL_EXECUTABLE "perl")
  26. endif()
  27. if(NOT GO_EXECUTABLE)
  28. set(GO_EXECUTABLE "go")
  29. endif()
  30. else()
  31. find_package(Perl REQUIRED)
  32. find_program(GO_EXECUTABLE go)
  33. endif()
  34. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_CROSSCOMPILING)
  35. find_package(PkgConfig QUIET)
  36. if (PkgConfig_FOUND)
  37. pkg_check_modules(LIBUNWIND libunwind-generic)
  38. if(LIBUNWIND_FOUND)
  39. add_definitions(-DBORINGSSL_HAVE_LIBUNWIND)
  40. else()
  41. message("libunwind not found. Disabling unwind tests.")
  42. endif()
  43. else()
  44. message("pkgconfig not found. Disabling unwind tests.")
  45. endif()
  46. endif()
  47. if(NOT GO_EXECUTABLE)
  48. message(FATAL_ERROR "Could not find Go")
  49. endif()
  50. if(USE_CUSTOM_LIBCXX)
  51. set(BORINGSSL_ALLOW_CXX_RUNTIME 1)
  52. endif()
  53. if(BORINGSSL_ALLOW_CXX_RUNTIME)
  54. add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME)
  55. endif()
  56. if(CMAKE_BUILD_TYPE STREQUAL "Release")
  57. # Windows release builds don't set NDEBUG in NASM flags automatically.
  58. set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DNDEBUG")
  59. endif()
  60. # Add a RelWithAsserts build configuration. It is the same as Release, except it
  61. # does not define NDEBUG, so asserts run.
  62. foreach(VAR CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_ASM_FLAGS)
  63. string(REGEX REPLACE "(^| )[/-]DNDEBUG( |$)" " " "${VAR}_RELWITHASSERTS"
  64. "${${VAR}_RELEASE}")
  65. endforeach()
  66. if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS)
  67. add_definitions(-DBORINGSSL_PREFIX=${BORINGSSL_PREFIX})
  68. # CMake automatically connects include_directories to the NASM command-line,
  69. # but not add_definitions.
  70. set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}")
  71. # Use "symbol_prefix_include" to store generated header files
  72. include_directories(${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include)
  73. add_custom_command(
  74. OUTPUT symbol_prefix_include/boringssl_prefix_symbols.h
  75. symbol_prefix_include/boringssl_prefix_symbols_asm.h
  76. symbol_prefix_include/boringssl_prefix_symbols_nasm.inc
  77. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include
  78. COMMAND ${GO_EXECUTABLE} run ${CMAKE_CURRENT_SOURCE_DIR}/util/make_prefix_headers.go -out ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include ${BORINGSSL_PREFIX_SYMBOLS}
  79. DEPENDS util/make_prefix_headers.go
  80. ${CMAKE_BINARY_DIR}/${BORINGSSL_PREFIX_SYMBOLS})
  81. # add_dependencies needs a target, not a file, so we add an intermediate
  82. # target.
  83. add_custom_target(
  84. boringssl_prefix_symbols
  85. DEPENDS symbol_prefix_include/boringssl_prefix_symbols.h
  86. symbol_prefix_include/boringssl_prefix_symbols_asm.h
  87. symbol_prefix_include/boringssl_prefix_symbols_nasm.inc)
  88. add_dependencies(global_target boringssl_prefix_symbols)
  89. elseif(BORINGSSL_PREFIX OR BORINGSSL_PREFIX_SYMBOLS)
  90. message(FATAL_ERROR "Must specify both or neither of BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS")
  91. endif()
  92. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  93. set(CLANG 1)
  94. endif()
  95. if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
  96. # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
  97. # primarily on our normal Clang one.
  98. set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings")
  99. if(MSVC)
  100. # clang-cl sets different default warnings than clang. It also treats -Wall
  101. # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall.
  102. # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116
  103. set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900")
  104. # googletest suppresses warning C4996 via a pragma, but clang-cl does not
  105. # honor it. Suppress it here to compensate. See https://crbug.com/772117.
  106. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations")
  107. else()
  108. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -ggdb -fvisibility=hidden -fno-common")
  109. endif()
  110. if(CLANG)
  111. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
  112. else()
  113. # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
  114. # and declare that the code is trying to free a stack pointer.
  115. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object")
  116. endif()
  117. if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
  118. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
  119. endif()
  120. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
  121. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
  122. if(NOT MSVC)
  123. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  124. if(APPLE)
  125. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  126. endif()
  127. if(NOT BORINGSSL_ALLOW_CXX_RUNTIME)
  128. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
  129. endif()
  130. endif()
  131. # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
  132. # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
  133. # spelling for both and -Wmissing-declarations is some other warning.
  134. #
  135. # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
  136. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
  137. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
  138. if(CLANG)
  139. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
  140. endif()
  141. if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
  142. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
  143. endif()
  144. elseif(MSVC)
  145. set(MSVC_DISABLED_WARNINGS_LIST
  146. "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not
  147. # explicitly handled by a case label
  148. # Disable this because it flags even when there is a default.
  149. "C4100" # 'exarg' : unreferenced formal parameter
  150. "C4127" # conditional expression is constant
  151. "C4200" # nonstandard extension used : zero-sized array in
  152. # struct/union.
  153. "C4204" # nonstandard extension used: non-constant aggregate initializer
  154. "C4221" # nonstandard extension used : 'identifier' : cannot be
  155. # initialized using address of automatic variable
  156. "C4242" # 'function' : conversion from 'int' to 'uint8_t',
  157. # possible loss of data
  158. "C4244" # 'function' : conversion from 'int' to 'uint8_t',
  159. # possible loss of data
  160. "C4267" # conversion from 'size_t' to 'int', possible loss of data
  161. "C4371" # layout of class may have changed from a previous version of the
  162. # compiler due to better packing of member '...'
  163. "C4388" # signed/unsigned mismatch
  164. "C4296" # '>=' : expression is always true
  165. "C4350" # behavior change: 'std::_Wrap_alloc...'
  166. "C4365" # '=' : conversion from 'size_t' to 'int',
  167. # signed/unsigned mismatch
  168. "C4389" # '!=' : signed/unsigned mismatch
  169. "C4464" # relative include path contains '..'
  170. "C4510" # 'argument' : default constructor could not be generated
  171. "C4512" # 'argument' : assignment operator could not be generated
  172. "C4514" # 'function': unreferenced inline function has been removed
  173. "C4548" # expression before comma has no effect; expected expression with
  174. # side-effect" caused by FD_* macros.
  175. "C4610" # struct 'argument' can never be instantiated - user defined
  176. # constructor required.
  177. "C4623" # default constructor was implicitly defined as deleted
  178. "C4625" # copy constructor could not be generated because a base class
  179. # copy constructor is inaccessible or deleted
  180. "C4626" # assignment operator could not be generated because a base class
  181. # assignment operator is inaccessible or deleted
  182. "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with
  183. # '0' for 'directives'
  184. # Disable this because GTest uses it everywhere.
  185. "C4706" # assignment within conditional expression
  186. "C4710" # 'function': function not inlined
  187. "C4711" # function 'function' selected for inline expansion
  188. "C4800" # 'int' : forcing value to bool 'true' or 'false'
  189. # (performance warning)
  190. "C4820" # 'bytes' bytes padding added after construct 'member_name'
  191. "C5026" # move constructor was implicitly defined as deleted
  192. "C5027" # move assignment operator was implicitly defined as deleted
  193. "C5045" # Compiler will insert Spectre mitigation for memory load if
  194. # /Qspectre switch specified
  195. )
  196. set(MSVC_LEVEL4_WARNINGS_LIST
  197. # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
  198. "C4265" # class has virtual functions, but destructor is not virtual
  199. )
  200. string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
  201. ${MSVC_DISABLED_WARNINGS_LIST})
  202. string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
  203. ${MSVC_LEVEL4_WARNINGS_LIST})
  204. set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  205. set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  206. endif()
  207. if(WIN32)
  208. add_definitions(-D_HAS_EXCEPTIONS=0)
  209. add_definitions(-DWIN32_LEAN_AND_MEAN)
  210. add_definitions(-DNOMINMAX)
  211. # Allow use of fopen.
  212. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  213. # VS 2017 and higher supports STL-only warning suppressions. Manually add to
  214. # C++ only to work around a CMake quoting bug when using NASM with the Visual
  215. # Studio generator. This will be fixed in CMake 3.13.0. See
  216. # https://gitlab.kitware.com/cmake/cmake/merge_requests/2179
  217. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_STL_EXTRA_DISABLED_WARNINGS=4774\ 4987>)
  218. endif()
  219. if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
  220. CLANG)
  221. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
  222. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
  223. endif()
  224. if(CMAKE_COMPILER_IS_GNUCXX)
  225. if((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
  226. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
  227. else()
  228. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
  229. endif()
  230. endif()
  231. # pthread_rwlock_t requires a feature flag.
  232. if(NOT WIN32)
  233. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
  234. endif()
  235. if(FUZZ)
  236. if(NOT CLANG)
  237. message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
  238. endif()
  239. if(CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0")
  240. message(FATAL_ERROR "You need Clang ≥ 6.0.0")
  241. endif()
  242. add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
  243. set(RUNNER_ARGS "-deterministic")
  244. if(NOT NO_FUZZER_MODE)
  245. add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
  246. set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
  247. endif()
  248. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls")
  249. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls")
  250. endif()
  251. add_definitions(-DBORINGSSL_IMPLEMENTATION)
  252. if(BUILD_SHARED_LIBS)
  253. add_definitions(-DBORINGSSL_SHARED_LIBRARY)
  254. # Enable position-independent code globally. This is needed because
  255. # some library targets are OBJECT libraries.
  256. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  257. endif()
  258. if(MSAN)
  259. if(NOT CLANG)
  260. message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
  261. endif()
  262. if(ASAN)
  263. message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
  264. endif()
  265. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
  266. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
  267. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
  268. endif()
  269. if(ASAN)
  270. if(NOT CLANG)
  271. message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
  272. endif()
  273. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  274. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  275. endif()
  276. if(CFI)
  277. if(NOT CLANG)
  278. message(FATAL_ERROR "Cannot enable CFI unless using Clang")
  279. endif()
  280. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin")
  281. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin")
  282. # We use Chromium's copy of clang, which requires -fuse-ld=lld if building
  283. # with -flto. That, in turn, can't handle -ggdb.
  284. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
  285. string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  286. string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  287. # -flto causes object files to contain LLVM bitcode. Mixing those with
  288. # assembly output in the same static library breaks the linker.
  289. set(OPENSSL_NO_ASM "1")
  290. endif()
  291. if(TSAN)
  292. if(NOT CLANG)
  293. message(FATAL_ERROR "Cannot enable TSAN unless using Clang")
  294. endif()
  295. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
  296. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
  297. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
  298. endif()
  299. if(UBSAN)
  300. if(NOT CLANG)
  301. message(FATAL_ERROR "Cannot enable UBSAN unless using Clang")
  302. endif()
  303. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
  304. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
  305. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
  306. if(NOT UBSAN_RECOVER)
  307. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover=undefined")
  308. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=undefined")
  309. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-sanitize-recover=undefined")
  310. endif()
  311. endif()
  312. if(GCOV)
  313. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  314. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  315. endif()
  316. if(FIPS)
  317. add_definitions(-DBORINGSSL_FIPS)
  318. if(FIPS_BREAK_TEST)
  319. add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
  320. endif()
  321. # Delocate does not work for ASan and MSan builds.
  322. if(NOT ASAN AND NOT MSAN)
  323. set(FIPS_DELOCATE "1")
  324. endif()
  325. endif()
  326. if(OPENSSL_SMALL)
  327. add_definitions(-DOPENSSL_SMALL)
  328. endif()
  329. if(CONSTANT_TIME_VALIDATION)
  330. add_definitions(-DBORINGSSL_CONSTANT_TIME_VALIDATION)
  331. # Asserts will often test secret data.
  332. add_definitions(-DNDEBUG)
  333. endif()
  334. function(go_executable dest package)
  335. set(godeps "${CMAKE_SOURCE_DIR}/util/godeps.go")
  336. if(${CMAKE_VERSION} VERSION_LESS "3.7" OR
  337. NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
  338. # The DEPFILE parameter to add_custom_command is new as of CMake 3.7 and
  339. # only works with Ninja. Query the sources at configure time. Additionally,
  340. # everything depends on go.mod. That affects what external packages to use.
  341. execute_process(COMMAND ${GO_EXECUTABLE} run ${godeps} -format cmake
  342. -pkg ${package}
  343. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  344. OUTPUT_VARIABLE sources
  345. RESULT_VARIABLE godeps_result)
  346. add_custom_command(OUTPUT ${dest}
  347. COMMAND ${GO_EXECUTABLE} build
  348. -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package}
  349. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  350. DEPENDS ${sources} ${CMAKE_SOURCE_DIR}/go.mod)
  351. else()
  352. # Ninja expects the target in the depfile to match the output. This is a
  353. # relative path from the build directory.
  354. string(LENGTH "${CMAKE_BINARY_DIR}" root_dir_length)
  355. math(EXPR root_dir_length "${root_dir_length} + 1")
  356. string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}" ${root_dir_length} -1 target)
  357. set(target "${target}/${dest}")
  358. set(depfile "${CMAKE_CURRENT_BINARY_DIR}/${dest}.d")
  359. add_custom_command(OUTPUT ${dest}
  360. COMMAND ${GO_EXECUTABLE} build
  361. -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package}
  362. COMMAND ${GO_EXECUTABLE} run ${godeps} -format depfile
  363. -target ${target} -pkg ${package} -out ${depfile}
  364. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  365. DEPENDS ${godeps} ${CMAKE_SOURCE_DIR}/go.mod
  366. DEPFILE ${depfile})
  367. endif()
  368. endfunction()
  369. # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
  370. # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
  371. # alone, and expects all architecture-specific logic to be conditioned within
  372. # the source files rather than the build. This does not work for our assembly
  373. # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
  374. # builds.
  375. if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
  376. list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
  377. if(NOT ${NUM_ARCHES} EQUAL 1)
  378. message(FATAL_ERROR "Universal binaries not supported.")
  379. endif()
  380. list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
  381. endif()
  382. if(OPENSSL_NO_ASM)
  383. add_definitions(-DOPENSSL_NO_ASM)
  384. set(ARCH "generic")
  385. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  386. set(ARCH "x86_64")
  387. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  388. set(ARCH "x86_64")
  389. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  390. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
  391. if(CMAKE_CL_64)
  392. set(ARCH "x86_64")
  393. else()
  394. set(ARCH "x86")
  395. endif()
  396. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  397. set(ARCH "x86")
  398. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  399. set(ARCH "x86")
  400. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  401. set(ARCH "x86")
  402. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  403. set(ARCH "aarch64")
  404. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
  405. set(ARCH "aarch64")
  406. # Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture.
  407. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64e")
  408. set(ARCH "aarch64")
  409. elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
  410. set(ARCH "arm")
  411. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
  412. # Just to avoid the “unknown processor” error.
  413. set(ARCH "generic")
  414. elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
  415. set(ARCH "ppc64le")
  416. else()
  417. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  418. endif()
  419. if(ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm")
  420. # The third-party Android-NDK CMake files somehow fail to set the -march flag
  421. # for assembly files. Without this flag, the compiler believes that it's
  422. # building for ARMv5.
  423. set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}")
  424. endif()
  425. if(${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
  426. # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
  427. # but clang defaults to 64-bit builds on OS X unless otherwise told.
  428. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
  429. set(ARCH "x86_64")
  430. endif()
  431. if(USE_CUSTOM_LIBCXX)
  432. if(NOT CLANG)
  433. message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang")
  434. endif()
  435. # CMAKE_CXX_FLAGS ends up in the linker flags as well, so use
  436. # add_compile_options. There does not appear to be a way to set
  437. # language-specific compile-only flags.
  438. add_compile_options("-nostdinc++")
  439. set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib++")
  440. include_directories(
  441. SYSTEM
  442. util/bot/libcxx/include
  443. util/bot/libcxxabi/include
  444. )
  445. # This is patterned after buildtools/third_party/libc++/BUILD.gn and
  446. # buildtools/third_party/libc++abi/BUILD.gn in Chromium.
  447. file(GLOB LIBCXX_SOURCES "util/bot/libcxx/src/*.cpp")
  448. file(GLOB LIBCXXABI_SOURCES "util/bot/libcxxabi/src/*.cpp")
  449. # This file is meant for exception-less builds.
  450. list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp")
  451. # libc++ also defines new and delete.
  452. list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp")
  453. if(TSAN)
  454. # ThreadSanitizer tries to intercept these symbols. Skip them to avoid
  455. # symbol conflicts.
  456. list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp")
  457. endif()
  458. add_library(libcxxabi ${LIBCXXABI_SOURCES})
  459. target_compile_definitions(
  460. libcxxabi PRIVATE
  461. -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
  462. )
  463. set_target_properties(libcxxabi PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough")
  464. add_library(libcxx ${LIBCXX_SOURCES})
  465. if(ASAN OR MSAN OR TSAN)
  466. # Sanitizers try to intercept new and delete.
  467. target_compile_definitions(
  468. libcxx PRIVATE
  469. -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS
  470. )
  471. endif()
  472. target_compile_definitions(
  473. libcxx PRIVATE
  474. -D_LIBCPP_BUILDING_LIBRARY
  475. -DLIBCXX_BUILDING_LIBCXXABI
  476. )
  477. target_link_libraries(libcxx libcxxabi)
  478. endif()
  479. # Add minimal googletest targets. The provided one has many side-effects, and
  480. # googletest has a very straightforward build.
  481. add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc)
  482. target_include_directories(boringssl_gtest PRIVATE third_party/googletest)
  483. include_directories(third_party/googletest/include)
  484. # Declare a dummy target to build all unit tests. Test targets should inject
  485. # themselves as dependencies next to the target definition.
  486. add_custom_target(all_tests)
  487. add_custom_command(
  488. OUTPUT crypto_test_data.cc
  489. COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} >
  490. ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc
  491. DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA}
  492. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  493. add_library(crypto_test_data OBJECT crypto_test_data.cc)
  494. add_subdirectory(crypto)
  495. add_subdirectory(ssl)
  496. add_subdirectory(ssl/test)
  497. add_subdirectory(fipstools)
  498. add_subdirectory(tool)
  499. add_subdirectory(decrepit)
  500. if(FUZZ)
  501. if(LIBFUZZER_FROM_DEPS)
  502. file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
  503. add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
  504. # libFuzzer does not pass our aggressive warnings. It also must be built
  505. # without -fsanitize-coverage options or clang crashes.
  506. set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0")
  507. endif()
  508. add_subdirectory(fuzz)
  509. endif()
  510. if(NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
  511. # USES_TERMINAL is only available in CMake 3.2 or later.
  512. set(MAYBE_USES_TERMINAL USES_TERMINAL)
  513. endif()
  514. if(UNIX AND NOT APPLE AND NOT ANDROID)
  515. set(HANDSHAKER_ARGS "-handshaker-path" $<TARGET_FILE:handshaker>)
  516. endif()
  517. add_custom_target(
  518. run_tests
  519. COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
  520. ${CMAKE_BINARY_DIR}
  521. COMMAND cd ssl/test/runner &&
  522. ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
  523. ${HANDSHAKER_ARGS} ${RUNNER_ARGS}
  524. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  525. DEPENDS all_tests bssl_shim handshaker
  526. ${MAYBE_USES_TERMINAL})