Skip to content

Commit

Permalink
finishing cmake work; fixing interop
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Hewett committed Aug 29, 2023
1 parent 36f14bc commit 0581f15
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 140 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ out
*.swp
.vs/**
.vscode/**
include/namespace.h
53 changes: 21 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
cmake_minimum_required(VERSION 3.12)

project(mlspp
VERSION 3.0.1
VERSION 0.1
LANGUAGES CXX
)

option(TESTING "Build tests" OFF)
option(CLANG_TIDY "Perform linting with clang-tidy" OFF)
option(SANITIZERS "Enable sanitizers" OFF)

# Default values for the namespaces are adequate for most uses.
set(MLS_CPP_NAMESPACE "mls" CACHE STRING "top-level namespace for cpp")
set(MLS_EXPORT_NAMESPACE "MLSPP" CACHE STRING "namespace for cmake export")

###
### Global Config
###
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

###
### Determine Namespacing
### Using the version number of the project to create the namespace.
### 3.0.0 -> v3
### 3.1.0 -> v3_1
### 3.1.1 -> v3_1_1
###
set(MLS_NAMESPACE_VERSION "v${PROJECT_VERSION}")
string(REPLACE "." "_" MLS_NAMESPACE_VERSION ${MLS_NAMESPACE_VERSION})
string(REGEX REPLACE "_0$" "" MLS_NAMESPACE_VERSION ${MLS_NAMESPACE_VERSION})
string(REGEX REPLACE "_0$" "" MLS_NAMESPACE_VERSION ${MLS_NAMESPACE_VERSION})
set(MLS_CPP_NAMESPACE "mls${MLS_NAMESPACE_VERSION}")
set(MLS_CMAKE_NAMESPACE "MLSPP${MLS_NAMESPACE_VERSION}")
set(MLS_CMAKE_CONFIG_NAME "mlspp${MLS_NAMESPACE_VERSION}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/namespace.h.in"
"${CMAKE_BINARY_DIR}/include/namespace.h" @ONLY)
include_directories("${CMAKE_BINARY_DIR}/include")
message(STATUS "MLS_CPP_NAMESPACE: ${MLS_CPP_NAMESPACE}")
message(STATUS "MLS_CMAKE_NAMESPACE: ${MLS_CMAKE_NAMESPACE}")
message(STATUS "MLS_CMAKE_CONFIG_NAME: ${MLS_CMAKE_CONFIG_NAME}")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/include/namespace.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/include/namespace.h"
@ONLY
)

include(CheckCXXCompilerFlag)
include(CMakePackageConfigHelpers)
Expand Down Expand Up @@ -130,7 +119,7 @@ target_link_libraries(${LIB_NAME} bytes tls_syntax hpke)
target_include_directories(${LIB_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${MLS_CPP_NAMESPACE}>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
PRIVATE
${OPENSSL_INCLUDE_DIR}
)
Expand All @@ -149,17 +138,17 @@ endif()
###
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
export(EXPORT mlspp-targets
NAMESPACE ${MLS_CMAKE_NAMESPACE}::
FILE ${CMAKE_CURRENT_BINARY_DIR}/${MLS_CMAKE_CONFIG_NAME}-targets.cmake)
export(PACKAGE ${MLS_CMAKE_NAMESPACE})
NAMESPACE ${MLS_EXPORT_NAMESPACE}::
FILE ${CMAKE_CURRENT_BINARY_DIR}/${MLS_EXPORT_NAMESPACE}Targets.cmake)
export(PACKAGE ${MLS_EXPORT_NAMESPACE})

configure_package_config_file(cmake/config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${MLS_CMAKE_CONFIG_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MLS_EXPORT_NAMESPACE}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/mlspp
NO_SET_AND_CHECK_MACRO)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${MLS_CMAKE_CONFIG_NAME}-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MLS_EXPORT_NAMESPACE}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

Expand All @@ -171,13 +160,13 @@ install(
DIRECTORY
include/
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/${MLS_CPP_NAMESPACE})
${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${MLS_CMAKE_CONFIG_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MLS_CMAKE_CONFIG_NAME}-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MLS_CMAKE_CONFIG_NAME}-targets.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MLS_EXPORT_NAMESPACE}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MLS_EXPORT_NAMESPACE}ConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/${MLS_EXPORT_NAMESPACE}Targets.cmake
DESTINATION
${CMAKE_INSTALL_DATADIR}/${MLS_CPP_NAMESPACE})
${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})

2 changes: 1 addition & 1 deletion cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/@MLS_CMAKE_CONFIG_NAME@-targets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/@MLS_EXPORT_NAMESPACE@Targets.cmake)
check_required_components(mlspp)
19 changes: 10 additions & 9 deletions cmd/interop/src/json_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct adl_serializer<std::optional<T>>
};

// LeafCount, NodeCount, etc.
// XXX(RLB): For some reason, just defining this for MLS_NAMESPACE::Uint32 didn't work.
// XXX(RLB): For some reason, just defining this for MLS_NAMESPACE::Uint32
// didn't work.
template<typename T>
struct uint_serializer
{
Expand All @@ -54,8 +55,7 @@ struct uint_serializer
#define UINT_SERIALIZER(T) \
template<> \
struct adl_serializer<T> : uint_serializer<T> \
{ \
};
{};

UINT_SERIALIZER(MLS_NAMESPACE::LeafCount)
UINT_SERIALIZER(MLS_NAMESPACE::NodeCount)
Expand Down Expand Up @@ -94,8 +94,7 @@ struct asymmetric_key_serializer
#define ASYMM_KEY_SERIALIZER(T) \
template<> \
struct adl_serializer<T> : asymmetric_key_serializer<T> \
{ \
};
{};

ASYMM_KEY_SERIALIZER(MLS_NAMESPACE::HPKEPublicKey)
ASYMM_KEY_SERIALIZER(MLS_NAMESPACE::HPKEPrivateKey)
Expand All @@ -106,19 +105,21 @@ ASYMM_KEY_SERIALIZER(MLS_NAMESPACE::SignaturePrivateKey)
template<typename T>
struct tls_serializer
{
static void to_json(json& j, const T& v) { j = bytes(tls::marshal(v)); }
static void to_json(json& j, const T& v)
{
j = bytes(MLS_NAMESPACE::tls::marshal(v));
}

static void from_json(const json& j, T& v)
{
v = tls::get<T>(j.get<bytes>());
v = MLS_NAMESPACE::tls::get<T>(j.get<bytes>());
}
};

#define TLS_SERIALIZER(T) \
template<> \
struct adl_serializer<T> : tls_serializer<T> \
{ \
};
{};

TLS_SERIALIZER(MLS_NAMESPACE::TreeKEMPublicKey)
TLS_SERIALIZER(MLS_NAMESPACE::AuthenticatedContent)
Expand Down
3 changes: 2 additions & 1 deletion cmd/interop/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ make_test_vector(uint64_t type)
case TestVectorClass::tree_modifications: {
auto cases = std::vector<TreeOperationsTestVector>();

auto suite = MLS_NAMESPACE::CipherSuite::ID::X25519_AES128GCM_SHA256_Ed25519;
auto suite =
MLS_NAMESPACE::CipherSuite::ID::X25519_AES128GCM_SHA256_Ed25519;
for (auto scenario : TreeOperationsTestVector::all_scenarios) {
cases.emplace_back(suite, scenario);
}
Expand Down
Loading

0 comments on commit 0581f15

Please sign in to comment.