# CMakeList.txt : CMake project for noscrypt, include source and define # project specific logic here. # cmake_minimum_required (VERSION 3.10) project(noscrypt C) option(BUILD_TESTS "Build tests" TRUE) set(NOSCRYPT_SRCS "src/noscrypt.c" ) set(NOSCRYPT_HEADERS "src/noscrypt.h" ) include_directories(include) #static/shared library add_library(${CMAKE_PROJECT_NAME} SHARED ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS}) add_library(${CMAKE_PROJECT_NAME}_static STATIC ${NOSCRYPT_SRCS} ${NOSCRYPT_HEADERS}) #Setup the compiler options for c90 shared library set(CMAKE_C_STANDARD 90) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC c_std_90) #if debug add_compile_definitions($<$:DEBUG>) #when building we are in libary mode, we need to export our symbols add_compile_definitions(NOSCRYPT_EXPORTING) #setup flags for windows compilation if(MSVC) #global windows cl flags add_compile_options( /sdl #enable additional security checks /TC #compile as c /GS #buffer security check $<$:/FC> #show full path in diagnostics $<$:/showIncludes> #show a list of all included header files during build $<$:/wd4820> #disable warnings for struct padding and spectre mitigation wuen WX is enabled $<$:/wd5045> #disable warnings for spectre mitigation insertion #for debug configs $<$:/options:strict> $<$:/Wall> #enable all warnings $<$:/WX> #warnings as errors (only for our project) $<$:/Zi> #enable rich debug info $<$:/Zo> ) #set build macros add_compile_definitions( $<$:DEBUG> $<$:RELEASE> ) #configure gcc flags elseif(CMAKE_COMPILER_IS_GNUCC) add_compile_options( -Wextra -fstack-protector $<$:-g> $<$:-Og> $<$:-Wall> $<$:-Werror> $<$:-Wall> $<$:-pedantic> ) endif() # Setup secp256k1 shared libary unset(SECP256K1_LIB CACHE) find_library(SECP256K1_LIB NAMES secp256k1 libsecp256k1 lib_secp256k1 PATHS ${LOCAL_SECP256K1_DIR}/src ) if(NOT SECP256K1_LIB) message(FATAL_ERROR "secp256k1 library not found on local system") endif() message(STATUS "secp256k1 library found at ${SECP256K1_LIB}") target_link_libraries(${CMAKE_PROJECT_NAME} ${SECP256K1_LIB}) #link mbedtls and mbedcrypto shared libraries unset(MBEDCRYPTO_LIB CACHE) unset(MBEDTLS_LIB CACHE) find_library(MBEDTLS_LIB NAMES mbedtls libmbedtls PATHS ${LOCAL_MBEDTLS_DIR}/library ) find_library(MBEDCRYPTO_LIB NAMES mbedcrypto libmbedcrypto PATHS ${LOCAL_MBEDTLS_DIR}/library ) if(NOT MBEDCRYPTO_LIB) message(FATAL_ERROR "mbedcrypto library not found on local system") endif() if(NOT MBEDTLS_LIB) message(FATAL_ERROR "mbedtls library not found on local system") endif() message(STATUS "mbedtls library found at ${MBEDTLS_LIB}") message(STATUS "mbedcrypto library found at ${MBEDCRYPTO_LIB}") target_link_libraries(${CMAKE_PROJECT_NAME} ${MBEDCRYPTO_LIB} ${MBEDTLS_LIB}) #TESTS if(BUILD_TESTS) #add test executable and link to library add_executable(nctest tests/test.c) target_link_libraries(nctest ${CMAKE_PROJECT_NAME}) #link mbedtls crypto shared library directly target_link_libraries(nctest ${MBEDCRYPTO_LIB} ${MBEDTLS_LIB}) target_include_directories(nctest PRIVATE "src") #enable c11 for testing target_compile_features(nctest PRIVATE c_std_11) endif() # Enable Hot Reload for MSVC compilers if supported. if (POLICY CMP0141) cmake_policy(SET CMP0141 NEW) set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") endif()