Skip to content

Commit 2f77e93

Browse files
authored
Merge pull request #64 from cisco/ns-config
Make namespaces configurable
2 parents d626788 + fda711b commit 2f77e93

File tree

18 files changed

+61
-33
lines changed

18 files changed

+61
-33
lines changed

CMakeLists.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ option(TESTING "Build tests" OFF)
99
option(CLANG_TIDY "Perform linting with clang-tidy" OFF)
1010
option(SANITIZERS "Enable sanitizers" OFF)
1111
option(NO_ALLOC "Build without needing an allocator" OFF)
12+
option(NAMESPACE_SUFFIX "Namespace Suffix for CXX and CMake Export")
13+
14+
if(NAMESPACE_SUFFIX)
15+
set(SFRAME_CXX_NAMESPACE "sframe_${NAMESPACE_SUFFIX}" CACHE STRING "Top-level Namespace for CXX")
16+
set(SFRAME_EXPORT_NAMESPACE "SFrame${NAMESPACE_SUFFIX}" CACHE STRING "Namespace for CMake Export")
17+
else()
18+
set(SFRAME_CXX_NAMESPACE "sframe" CACHE STRING "Top-level Namespace for CXX")
19+
set(SFRAME_EXPORT_NAMESPACE "SFrame" CACHE STRING "Namespace for CMake Export")
20+
endif()
21+
message(STATUS "CXX Namespace: ${SFRAME_CXX_NAMESPACE}")
22+
message(STATUS "CMake Export Namespace: ${SFRAME_EXPORT_NAMESPACE}")
1223

1324
# Use -DCRYPTO=(OPENSSL_1_1 | OPENSSL_3 | BORINGSSL) to configure crypto
1425
if(NOT DEFINED CRYPTO)
@@ -20,6 +31,12 @@ endif()
2031
###
2132
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2233

34+
configure_file(
35+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/namespace.h.in"
36+
"${CMAKE_CURRENT_BINARY_DIR}/include/namespace.h"
37+
@ONLY
38+
)
39+
2340
set(CMAKE_CXX_STANDARD 17)
2441
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2542
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
@@ -87,13 +104,15 @@ endif()
87104
set(LIB_NAME "${PROJECT_NAME}")
88105

89106
file(GLOB_RECURSE LIB_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
107+
file(GLOB_RECURSE LIB_GENERATED_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/*.h")
90108
file(GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
91109

92-
add_library(${LIB_NAME} ${LIB_HEADERS} ${LIB_SOURCES})
110+
add_library(${LIB_NAME} ${LIB_HEADERS} ${LIB_GENERATED_HEADERS} ${LIB_SOURCES})
93111
target_link_libraries(${LIB_NAME} PRIVATE ${CRYPTO_LIB})
94112
target_include_directories(${LIB_NAME}
95113
PUBLIC
96-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
114+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
115+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
97116
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
98117
)
99118

cmake/namespace.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
// Configurable top-level namespace
4+
#define SFRAME_NAMESPACE @SFRAME_CXX_NAMESPACE@

include/sframe/map.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <sframe/vector.h>
66

7-
namespace sframe {
7+
namespace SFRAME_NAMESPACE {
88

99
template<typename K, typename V, size_t N>
1010
class map : private vector<std::optional<std::pair<K, V>>, N>
@@ -69,13 +69,14 @@ class map : private vector<std::optional<std::pair<K, V>>, N>
6969
}
7070
};
7171

72-
} // namespace sframe
72+
} // namespace SFRAME_NAMESPACE
7373

7474
#else // ifdef NO_ALLOC
7575

7676
#include <map>
77+
#include <namespace.h>
7778

78-
namespace sframe {
79+
namespace SFRAME_NAMESPACE {
7980

8081
// NOTE: NOT RECOMMENDED FOR USE OUTSIDE THIS LIBRARY
8182
//
@@ -106,6 +107,6 @@ class map : public std::map<K, V>
106107
}
107108
};
108109

109-
} // namespace sframe
110+
} // namespace SFRAME_NAMESPACE
110111

111112
#endif // def NO_ALLOC

include/sframe/sframe.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <sframe/map.h>
77
#include <sframe/vector.h>
88

9+
#include <namespace.h>
10+
911
// These constants define the size of certain internal data structures if
1012
// we are configured not to depend on dynamic allocations, i.e., if the NO_ALLOC
1113
// flag is set. If you are using an allocator, you can ignore them.
@@ -22,7 +24,7 @@
2224
#define SFRAME_EPOCH_BITS 4
2325
#endif
2426

25-
namespace sframe {
27+
namespace SFRAME_NAMESPACE {
2628

2729
struct crypto_error : std::runtime_error
2830
{
@@ -202,4 +204,4 @@ class MLSContext : protected Context
202204
vector<std::optional<EpochKeys>, max_epochs> epoch_cache;
203205
};
204206

205-
} // namespace sframe
207+
} // namespace SFRAME_NAMESPACE

include/sframe/vector.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#pragma once
22

33
#include <gsl/gsl-lite.hpp>
4+
#include <namespace.h>
45

56
#ifdef NO_ALLOC
67

7-
namespace sframe {
8+
namespace SFRAME_NAMESPACE {
89

910
template<typename T, size_t N>
1011
class vector
@@ -86,13 +87,13 @@ class vector
8687
operator gsl::span<T>() { return gsl::span(_data).first(_size); }
8788
};
8889

89-
} // namespace sframe
90+
} // namespace SFRAME_NAMESPACE
9091

9192
#else // ifdef NO_ALLOC
9293

9394
#include <vector>
9495

95-
namespace sframe {
96+
namespace SFRAME_NAMESPACE {
9697

9798
// NOTE: NOT RECOMMENDED FOR USE OUTSIDE THIS LIBRARY
9899
//
@@ -137,6 +138,6 @@ class vector : public std::vector<T>
137138
}
138139
};
139140

140-
} // namespace sframe
141+
} // namespace SFRAME_NAMESPACE
141142

142143
#endif // def NO_ALLOC

src/crypto.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "crypto.h"
22
#include "header.h"
33

4-
namespace sframe {
4+
namespace SFRAME_NAMESPACE {
55

66
size_t
77
cipher_digest_size(CipherSuite suite)
@@ -94,4 +94,4 @@ cipher_overhead(CipherSuite suite)
9494
}
9595
}
9696

97-
} // namespace sframe
97+
} // namespace SFRAME_NAMESPACE

src/crypto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <sframe/sframe.h>
44

5-
namespace sframe {
5+
namespace SFRAME_NAMESPACE {
66

77
size_t
88
cipher_digest_size(CipherSuite suite);
@@ -48,4 +48,4 @@ open(CipherSuite suite,
4848
input_bytes aad,
4949
input_bytes ct);
5050

51-
} // namespace sframe
51+
} // namespace SFRAME_NAMESPACE

src/crypto_boringssl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <openssl/hmac.h>
1010
#include <openssl/mem.h>
1111

12-
namespace sframe {
12+
namespace SFRAME_NAMESPACE {
1313

1414
///
1515
/// Convert between native identifiers / errors and OpenSSL ones
@@ -428,6 +428,6 @@ open(CipherSuite suite,
428428
throw unsupported_ciphersuite_error();
429429
}
430430

431-
} // namespace sframe
431+
} // namespace SFRAME_NAMESPACE
432432

433433
#endif // defined(OPENSSL_3)

src/crypto_openssl11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <openssl/evp.h>
88
#include <openssl/hmac.h>
99

10-
namespace sframe {
10+
namespace SFRAME_NAMESPACE {
1111

1212
///
1313
/// Scoped pointers for OpenSSL objects
@@ -466,6 +466,6 @@ open(CipherSuite suite,
466466
throw unsupported_ciphersuite_error();
467467
}
468468

469-
} // namespace sframe
469+
} // namespace SFRAME_NAMESPACE
470470

471471
#endif // defined(OPENSSL_1_1)

src/crypto_openssl3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <openssl/kdf.h>
1010
#include <openssl/params.h>
1111

12-
namespace sframe {
12+
namespace SFRAME_NAMESPACE {
1313

1414
///
1515
/// Convert between native identifiers / errors and OpenSSL ones
@@ -468,6 +468,6 @@ open(CipherSuite suite,
468468
throw unsupported_ciphersuite_error();
469469
}
470470

471-
} // namespace sframe
471+
} // namespace SFRAME_NAMESPACE
472472

473473
#endif // defined(OPENSSL_3)

0 commit comments

Comments
 (0)