Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
cmake_minimum_required(VERSION 3.28)
project(ncrypto)
project(ncrypto VERSION 1.0.1)

include(CTest)
include(GNUInstallDirs)
include(FetchContent)
include(cmake/ncrypto-flags.cmake)

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()

include(cmake/CPM.cmake)
if (NCRYPTO_SHARED_LIBS)
find_package(OpenSSL REQUIRED)
else()
include(FetchContent)
include(cmake/CPM.cmake)

CPMAddPackage(
CPMAddPackage(
NAME boringssl
VERSION 0.20250818.0
GITHUB_REPOSITORY google/boringssl
GIT_TAG 0.20250818.0
OPTIONS "BUILD_SHARED_LIBS OFF" "BUILD_TESTING OFF"
)
)
endif()

add_subdirectory(src)
add_library(ncrypto::ncrypto ALIAS ncrypto)

include_directories(${boringssl_SOURCE_DIR}/include)

if (NCRYPTO_TESTING)
CPMAddPackage(
if (NCRYPTO_SHARED_LIBS)
find_package(GTest REQUIRED)
else()
CPMAddPackage(
NAME GTest
GITHUB_REPOSITORY google/googletest
VERSION 1.15.2
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF"
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
enable_testing()
add_subdirectory(tests)
endif()
Expand All @@ -53,3 +60,15 @@ install(
ARCHIVE COMPONENT ncrypto_development
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

# Generate pkg-config file
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/ncrypto.pc.in
${CMAKE_CURRENT_BINARY_DIR}/ncrypto.pc
@ONLY
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/ncrypto.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
1 change: 1 addition & 0 deletions cmake/ncrypto-flags.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
option(NCRYPTO_DEVELOPMENT_CHECKS "development checks (useful for debugging)" OFF)
option(NCRYPTO_TESTING "Build tests" ON)
option(NCRYPTO_SHARED_LIBS "Build (and test) using shared library" OFF)
option(NCRYPTO_BSSL_LIBDECREPIT_MISSING "enable if boringssl is built without libdecrepit" OFF)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down
10 changes: 10 additions & 0 deletions ncrypto.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: ncrypto
Description: crypto functions for node:crypto
Version: @PROJECT_VERSION@
Libs: -L${libdir} -lncrypto
Cflags: -I${includedir}
15 changes: 9 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
add_library(ncrypto ncrypto.cpp engine.cpp)
target_link_libraries(ncrypto PUBLIC ssl crypto)

if (NCRYPTO_BSSL_LIBDECREPIT_MISSING)
target_compile_definitions(ncrypto PUBLIC NCRYPTO_BSSL_LIBDECREPIT_MISSING=1)
if (NCRYPTO_SHARED_LIBS)
target_link_libraries(ncrypto PUBLIC OpenSSL::SSL OpenSSL::Crypto)
else()
target_link_libraries(ncrypto PUBLIC decrepit)
endif()
target_link_libraries(ncrypto PUBLIC ssl crypto)

if (NCRYPTO_BSSL_LIBDECREPIT_MISSING)
target_compile_definitions(ncrypto PUBLIC NCRYPTO_BSSL_LIBDECREPIT_MISSING=1)
else()
target_link_libraries(ncrypto PUBLIC decrepit)
endif()
endif()
target_include_directories(ncrypto
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand Down