2018-05-19 12:40:20 -07:00
|
|
|
project(mycryptopp)
|
|
|
|
|
2018-05-19 14:18:35 -07:00
|
|
|
add_library(cryptopp dummy.cpp)
|
2018-05-20 13:33:16 -07:00
|
|
|
# note: include directory is called vendor_cryptopp instead of cryptopp to avoid include clashes with system headers
|
2018-05-19 14:18:35 -07:00
|
|
|
target_include_directories(cryptopp SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
|
2018-09-26 23:13:53 -07:00
|
|
|
# Forward debug build info (i.e. set CRYPTOPP_DEBUG variable if building in debug mode)
|
|
|
|
target_compile_definitions(cryptopp PUBLIC $<$<CONFIG:Debug>:CRYPTOPP_DEBUG>) # add to all targets depending on this
|
|
|
|
add_compile_options($<$<CONFIG:Debug>:-DCRYPTOPP_DEBUG>) # add to stuff built in subdirectories (like the actual library)
|
2018-07-08 19:58:52 -07:00
|
|
|
|
2018-05-20 14:15:18 -07:00
|
|
|
if(NOT DISABLE_OPENMP)
|
2018-09-27 23:31:26 -07:00
|
|
|
if (MSVC)
|
2018-09-26 00:21:21 -07:00
|
|
|
message(WARNING "MSVC does not support the OpenMP 4.0 standard used by Crypto++. Disabling OpenMP. This can cause degraded performance.")
|
2018-05-20 15:00:25 -07:00
|
|
|
else()
|
|
|
|
find_package(OpenMP)
|
2018-09-27 23:31:26 -07:00
|
|
|
|
|
|
|
if(NOT OPENMP_FOUND)
|
|
|
|
if((APPLE AND ((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")))
|
|
|
|
AND ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0") AND (CMAKE_VERSION VERSION_LESS "3.12.0")))
|
|
|
|
# Workaround because older cmake on apple doesn't support FindOpenMP
|
|
|
|
message(STATUS "Applying workaround for OSX OpenMP with old cmake that doesn't have FindOpenMP")
|
|
|
|
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
|
|
|
|
set(Additional_OpenMP_Libraries_Workaround "-lomp")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Did not find OpenMP. Build with -DDISABLE_OPENMP=ON if you want to allow this and are willing to take the performance hit.")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(Additional_OpenMP_Libraries_Workaround "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT TARGET OpenMP::OpenMP_CXX)
|
|
|
|
# We're on cmake < 3.9, handle behavior of the old FindOpenMP implementation
|
|
|
|
message(STATUS "Applying workaround for old CMake that doesn't define FindOpenMP using targets")
|
|
|
|
add_library(OpenMP_TARGET INTERFACE)
|
|
|
|
add_library(OpenMP::OpenMP_CXX ALIAS OpenMP_TARGET)
|
|
|
|
target_compile_options(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS}) # add to all targets depending on this
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
target_link_libraries(OpenMP_TARGET INTERFACE Threads::Threads)
|
|
|
|
target_link_libraries(OpenMP_TARGET INTERFACE ${OpenMP_CXX_FLAGS} ${Additional_OpenMP_Libraries_Workaround})
|
2018-09-25 00:41:03 -07:00
|
|
|
endif()
|
2018-09-27 23:31:26 -07:00
|
|
|
|
|
|
|
target_link_libraries(cryptopp PUBLIC OpenMP::OpenMP_CXX)
|
|
|
|
|
|
|
|
# also add these flags to the third party Crypto++ build setup that is built in a subdirectory
|
|
|
|
message(STATUS "OpenMP flags: ${OpenMP_CXX_FLAGS}")
|
|
|
|
string(REPLACE " " ";" REPLACED_FLAGS ${OpenMP_CXX_FLAGS})
|
|
|
|
add_compile_options(${REPLACED_FLAGS})
|
2018-05-20 15:00:25 -07:00
|
|
|
endif()
|
2018-09-27 23:31:26 -07:00
|
|
|
else()
|
2018-05-21 00:27:49 -07:00
|
|
|
message(WARNING "OpenMP is disabled. This can cause degraded performance.")
|
2018-09-27 23:31:26 -07:00
|
|
|
endif()
|
2018-05-19 14:18:35 -07:00
|
|
|
|
|
|
|
|
2018-05-19 11:22:51 -07:00
|
|
|
set(BUILD_TESTING OFF)
|
2018-05-19 12:40:20 -07:00
|
|
|
set(BUILD_DOCUMENTATION OFF)
|
|
|
|
set(BUILD_SHARED OFF)
|
|
|
|
set(BUILD_STATIC ON)
|
2018-05-20 13:33:16 -07:00
|
|
|
add_subdirectory(vendor_cryptopp EXCLUDE_FROM_ALL)
|
2018-05-19 12:40:20 -07:00
|
|
|
|
|
|
|
target_link_libraries(cryptopp PRIVATE cryptopp-static)
|