Skip to content

Commit f489098

Browse files
authored
CXXCBC-733: Fix build with BoringSSL (#839)
1 parent c2ab08b commit f489098

File tree

9 files changed

+74
-14
lines changed

9 files changed

+74
-14
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ if(COUCHBASE_CXX_CLIENT_BUILD_SHARED OR BUILD_SHARED_LIBS)
466466
set_target_properties(couchbase_cxx_client PROPERTIES VERSION ${couchbase_cxx_client_VERSION_MAJOR}
467467
SOVERSION ${couchbase_cxx_client_VERSION})
468468
list(APPEND couchbase_cxx_client_LIBRARIES couchbase_cxx_client)
469-
if (NOT WIN32)
469+
if(NOT WIN32)
470470
set(couchbase_cxx_client_DEFAULT_LIBRARY couchbase_cxx_client::couchbase_cxx_client)
471471
endif()
472472
endif()
@@ -543,8 +543,8 @@ foreach(TARGET ${couchbase_cxx_client_LIBRARIES})
543543
endif()
544544
target_link_libraries(${TARGET} PRIVATE $<BUILD_INTERFACE:ssl> $<BUILD_INTERFACE:crypto>)
545545
target_include_directories(
546-
${TARGET} SYSTEM PRIVATE $<BUILD_INTERFACE:$<TARGET_PROPERTY:ssl,INTERFACE_INCLUDE_DIRECTORIES>>
547-
$<BUILD_INTERFACE:$<TARGET_PROPERTY:crypto,INTERFACE_INCLUDE_DIRECTORIES>>)
546+
${TARGET} PRIVATE $<BUILD_INTERFACE:$<TARGET_PROPERTY:ssl,INTERFACE_INCLUDE_DIRECTORIES>>
547+
$<BUILD_INTERFACE:$<TARGET_PROPERTY:crypto,INTERFACE_INCLUDE_DIRECTORIES>>)
548548
else()
549549
if(TARGET PkgConfig::PKG_CONFIG_OPENSSL)
550550
target_link_libraries(${TARGET} PUBLIC PkgConfig::PKG_CONFIG_OPENSSL)

cmake/OpenSSL.cmake

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ elseif(COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL)
5454
)
5555
endif()
5656
endif()
57-
declare_system_library(ssl)
58-
declare_system_library(crypto)
5957
add_library(OpenSSL::SSL ALIAS ssl)
6058
add_library(OpenSSL::Crypto ALIAS crypto)
6159
else()
@@ -279,3 +277,17 @@ mozilla_ca_certs_sha256() -> std::string_view
279277
}
280278
} // namespace couchbase::core::default_ca
281279
")
280+
281+
set(OPENSSL_HEADERS_TO_PROXY
282+
crypto.h
283+
evp.h
284+
hmac.h
285+
md5.h
286+
rand.h
287+
sha.h
288+
ssl.h
289+
x509.h)
290+
foreach(HEADER_NAME IN LISTS OPENSSL_HEADERS_TO_PROXY)
291+
configure_file("${PROJECT_SOURCE_DIR}/cmake/include_ssl.hxx.in"
292+
"${CMAKE_CURRENT_BINARY_DIR}/generated/include_ssl/${HEADER_NAME}" @ONLY)
293+
endforeach()

cmake/Testing.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ endmacro()
203203

204204
add_library(test_main OBJECT ${PROJECT_SOURCE_DIR}/test/main.cxx)
205205
target_link_libraries(test_main PUBLIC Catch2::Catch2 OpenSSL::SSL)
206+
target_include_directories(test_main PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}/generated
207+
${PROJECT_BINARY_DIR}/generated_$<CONFIG>)
206208

207209
if(COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL AND WIN32)
208210
set_target_properties(test_main PROPERTIES LINK_FLAGS "/ignore:4099")

cmake/include_ssl.hxx.in

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2020-Present Couchbase, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#if defined(COUCHBASE_CXX_CLIENT_STATIC_BORINGSSL)
21+
22+
#include <openssl/is_boringssl.h>
23+
24+
#if defined(__GNUC__) || defined(__clang__)
25+
#pragma GCC diagnostic push
26+
#pragma GCC diagnostic ignored "-Wpragmas"
27+
#pragma GCC diagnostic ignored "-Wpedantic"
28+
#pragma GCC diagnostic ignored "-Wuseless-cast"
29+
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
30+
#pragma GCC diagnostic ignored "-Wnested-anon-types"
31+
#pragma GCC diagnostic ignored "-Wold-style-cast"
32+
#endif
33+
34+
#include <openssl/@HEADER_NAME@>
35+
36+
#if defined(__GNUC__) || defined(__clang__)
37+
#pragma GCC diagnostic pop
38+
#endif
39+
40+
#else
41+
42+
#include <openssl/@HEADER_NAME@>
43+
44+
#endif
45+
46+

core/crypto/cbcrypto.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,10 @@ decrypt(const couchbase::core::crypto::Cipher cipher,
589589

590590
#else
591591

592-
#include <openssl/evp.h>
593-
#include <openssl/hmac.h>
594-
#include <openssl/md5.h>
595-
#include <openssl/sha.h>
592+
#include "include_ssl/evp.h"
593+
#include "include_ssl/hmac.h"
594+
#include "include_ssl/md5.h"
595+
#include "include_ssl/sha.h"
596596

597597
// OpenSSL
598598

core/impl/crypto.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "core/mcbp/big_endian.hxx"
2424
#include "core/utils/binary.hxx"
2525

26-
#include <openssl/rand.h>
26+
#include "include_ssl/rand.h"
2727
#include <spdlog/fmt/bundled/format.h>
2828

2929
namespace couchbase::crypto::internal

core/meta/version.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
#include <couchbase/build_info.hxx>
2727
#include <couchbase/build_version.hxx>
2828

29+
#include "include_ssl/crypto.h"
30+
#include "include_ssl/x509.h"
2931
#include <asio/version.hpp>
3032
#include <hdr/hdr_histogram_version.h>
3133
#include <llhttp.h>
32-
#include <openssl/crypto.h>
33-
#include <openssl/x509.h>
3434
#include <snappy-stubs-public.h>
3535
#include <spdlog/fmt/bundled/core.h>
3636
#include <spdlog/version.h>

test/main.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <catch2/catch_session.hpp>
2121

22-
#include <openssl/ssl.h>
22+
#include "include_ssl/ssl.h"
2323

2424
auto
2525
main(int argc, char* argv[]) -> int

test/test_unit_utils.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include <couchbase/error_codes.hxx>
3535

36-
#include <openssl/crypto.h>
36+
#include "include_ssl/crypto.h"
3737
#include <tao/json.hpp>
3838

3939
TEST_CASE("unit: transformer to deduplicate JSON keys", "[unit]")

0 commit comments

Comments
 (0)