From 42c376f81b33174ad7a237c807e93ca726b3d25e Mon Sep 17 00:00:00 2001 From: OpenAI Date: Wed, 3 Jun 2026 10:34:55 +0000 Subject: [PATCH] Prefix MatrixSSL programs and improve submodule defaults --- CMakeLists.txt | 42 +++++++++++++++++++++++++++++++++++------- README.md | 4 ++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dcd5cb0..439b1e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,17 +3,35 @@ cmake_minimum_required(VERSION 3.16) project(matrixssl VERSION 4.6.0 LANGUAGES C) include(GNUInstallDirs) -include(CTest) + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(MATRIXSSL_TOP_LEVEL_BUILD TRUE) +else() + set(MATRIXSSL_TOP_LEVEL_BUILD FALSE) +endif() + +if(MATRIXSSL_TOP_LEVEL_BUILD) + include(CTest) +elseif(NOT DEFINED BUILD_TESTING) + set(BUILD_TESTING OFF) +endif() + +if(MATRIXSSL_TOP_LEVEL_BUILD) + set(MATRIXSSL_DEFAULT_BUILD_PROGRAMS ON) +else() + set(MATRIXSSL_DEFAULT_BUILD_PROGRAMS OFF) +endif() option(MATRIXSSL_BUILD_SHARED "Build MatrixSSL as a shared library" ON) option(MATRIXSSL_BUILD_STATIC "Build MatrixSSL as a static library" OFF) option(MATRIXSSL_DISABLE_TLS13 "Disable TLS 1.3 in the generated CMake configuration" ON) option(MATRIXSSL_BUILD_OPENSSL_COMPAT "Build the mars-nwe reduced OpenSSL compatibility layer" ON) -option(MATRIXSSL_BUILD_TESTS "Build MatrixSSL test programs matching the GNUmakefile tests target" ON) -option(MATRIXSSL_BUILD_APPS "Build MatrixSSL example applications matching the GNUmakefile apps target" ON) -option(MATRIXSSL_BUILD_TOOLS "Build auxiliary tools available from the legacy makefiles" ON) +option(MATRIXSSL_BUILD_TESTS "Build MatrixSSL test programs matching the GNUmakefile tests target" ${MATRIXSSL_DEFAULT_BUILD_PROGRAMS}) +option(MATRIXSSL_BUILD_APPS "Build MatrixSSL example applications matching the GNUmakefile apps target" ${MATRIXSSL_DEFAULT_BUILD_PROGRAMS}) +option(MATRIXSSL_BUILD_TOOLS "Build auxiliary tools available from the legacy makefiles" ${MATRIXSSL_DEFAULT_BUILD_PROGRAMS}) set(MATRIXSSL_CONFIG "default" CACHE STRING "MatrixSSL configuration directory under configs/") set(MATRIXSSL_LIBRARY_PREFIX "" CACHE STRING "Prefix added to installed library output names, e.g. 'nw' for libnwmatrixssl") +set(MATRIXSSL_PROGRAM_PREFIX "${MATRIXSSL_LIBRARY_PREFIX}" CACHE STRING "Prefix added to test, app, and tool executable/module output names. Defaults to MATRIXSSL_LIBRARY_PREFIX") set(MATRIXSSL_INSTALL_INCLUDE_SUBDIR "matrixssl" CACHE STRING "Header install subdirectory below CMAKE_INSTALL_INCLUDEDIR") set(MATRIXSSL_CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/configs/${MATRIXSSL_CONFIG}") @@ -355,17 +373,26 @@ function(matrixssl_link_program target_name) endif() endfunction() +function(matrixssl_prefixed_output_name output_var target_name) + string(REGEX REPLACE "^matrixssl_" "" _matrixssl_output_name "${target_name}") + set(${output_var} "${MATRIXSSL_PROGRAM_PREFIX}${_matrixssl_output_name}" PARENT_SCOPE) +endfunction() + function(matrixssl_add_test_program target_name) add_executable(${target_name} ${ARGN}) matrixssl_link_program(${target_name}) + matrixssl_prefixed_output_name(_matrixssl_test_output_name ${target_name}) set_target_properties(${target_name} PROPERTIES + OUTPUT_NAME "${_matrixssl_test_output_name}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests") endfunction() function(matrixssl_add_app_program target_name) add_executable(${target_name} ${ARGN}) matrixssl_link_program(${target_name}) + matrixssl_prefixed_output_name(_matrixssl_app_output_name ${target_name}) set_target_properties(${target_name} PROPERTIES + OUTPUT_NAME "${_matrixssl_app_output_name}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/apps") endfunction() @@ -427,8 +454,9 @@ if(MATRIXSSL_BUILD_APPS) apps/common/load_keys.c) matrixssl_link_program(matrixssl_client_common) target_compile_definitions(matrixssl_client_common PRIVATE ID_RSA) + matrixssl_prefixed_output_name(_matrixssl_client_common_output_name matrixssl_client_common) set_target_properties(matrixssl_client_common PROPERTIES - OUTPUT_NAME matrixssl_client_common + OUTPUT_NAME "${_matrixssl_client_common_output_name}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/apps") matrixssl_add_app_program(matrixssl_server apps/ssl/server.c apps/ssl/http.c) @@ -466,12 +494,12 @@ if(MATRIXSSL_BUILD_TOOLS) add_library(matrixssl_wrap_malloc MODULE core/wrapper/wrap-malloc.c) set_target_properties(matrixssl_wrap_malloc PROPERTIES PREFIX "" - OUTPUT_NAME "wrap-malloc" + OUTPUT_NAME "${MATRIXSSL_PROGRAM_PREFIX}wrap-malloc" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tools") target_compile_options(matrixssl_wrap_malloc PRIVATE -Wall -Werror) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tools") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tools/wrap-malloc-include.txt" - "EXTRA_CFLAGS=\"-include ${CMAKE_CURRENT_SOURCE_DIR}/core/wrapper/wrap-malloc.h\" EXTRA_LDFLAGS=\"${CMAKE_CURRENT_BINARY_DIR}/tools/wrap-malloc.so\"\n") + "EXTRA_CFLAGS=\"-include ${CMAKE_CURRENT_SOURCE_DIR}/core/wrapper/wrap-malloc.h\" EXTRA_LDFLAGS=\"${CMAKE_CURRENT_BINARY_DIR}/tools/${MATRIXSSL_PROGRAM_PREFIX}wrap-malloc.so\"\n") add_dependencies(matrixssl_tools matrixssl_wrap_malloc) endif() endif() diff --git a/README.md b/README.md index eb1f13c..031476e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ The CMake build also mirrors the legacy top-level Makefile more closely: Only safe smoke tests are registered with CTest. Interactive, benchmark, network server/client, and certificate-file tests are built but are not run automatically. +`MATRIXSSL_LIBRARY_PREFIX` changes the library output name, for example `-DMATRIXSSL_LIBRARY_PREFIX=nw` creates `libnwmatrixssl`. Test, app, and tool outputs use the same prefix by default through `MATRIXSSL_PROGRAM_PREFIX`, so the same build also creates names such as `nwserver`, `nwclient`, and `nwwrap-malloc.so`. Override `MATRIXSSL_PROGRAM_PREFIX` separately only when program names should differ from the library prefix. + +When MatrixSSL is included with `add_subdirectory()` from another CMake project, the library still builds by default but tests, apps, and auxiliary tools default to `OFF` to avoid adding legacy standalone programs to the parent project's normal build. They can still be enabled explicitly with `-DMATRIXSSL_BUILD_TESTS=ON`, `-DMATRIXSSL_BUILD_APPS=ON`, or `-DMATRIXSSL_BUILD_TOOLS=ON`. + Security note: this compatibility layer is intentionally small and mars-nwe-specific. It should not be presented as a general OpenSSL replacement. In particular, the FTK-facing X509/BIO helper surface is limited to the calls that code uses. ---