diff --git a/CMakeLists.txt b/CMakeLists.txt index 17a67e4e..18608c36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,16 @@ -cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR) +cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR) project(cryptopp) - -set(cryptopp_VERSION_MAJOR 5) -set(cryptopp_VERSION_MINOR 6) -set(cryptopp_VERSION_PATCH 3) +set(cryptopp_VERSION 5.6.3) include(GNUInstallDirs) include(TestBigEndian) include(CheckCXXSymbolExists) +if(POLICY CMP0042) + cmake_policy(SET CMP0042 NEW) +endif() + #============================================================================ # Settable options #============================================================================ @@ -26,18 +27,31 @@ set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory") # Internal compiler options #============================================================================ -set(LIB_VER ${cryptopp_VERSION_MAJOR}${cryptopp_VERSION_MINOR}${cryptopp_VERSION_PATCH}) +string(REPLACE "." ";" cryptopp_VERSION_LIST ${cryptopp_VERSION}) +list(GET cryptopp_VERSION_LIST 0 cryptopp_VERSION_MAJOR) +list(GET cryptopp_VERSION_LIST 1 cryptopp_VERSION_MINOR) +list(GET cryptopp_VERSION_LIST 2 cryptopp_VERSION_PATCH) + +math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}") if(CMAKE_CXX_COMPILER_ID MATCHES "Intel") add_definitions(-wd68 -wd186 -wd279 -wd327 -wd161 -wd3180) endif() # Endianess -TEST_BIG_ENDIAN(IS_BIG_ENDIAN) +test_big_endian(IS_BIG_ENDIAN) if(IS_BIG_ENDIAN) add_definitions(-DIS_BIG_ENDIAN) endif() +# Position independent code +if(BITS EQUAL 64) + # Enables -fPIC on all 64-bit platforms + set(cryptopp_POSITION_INDEPENDENT_CODE TRUE) +else() + set(cryptopp_POSITION_INDEPENDENT_CODE FALSE) +endif() + if(DISABLE_ASM) add_definitions(-DCRYPTOPP_DISABLE_ASM) endif() @@ -48,7 +62,7 @@ if(DISABLE_AESNI) add_definitions(-DCRYPTOPP_DISABLE_AESNI) endif() if(NOT CRYPTOPP_DATA_DIR STREQUAL "") - add_definitions(-DCRYPTOPP_DATA_DIR=${CRYPTOPP_DATA_DIR}) + add_definitions(-DCRYPTOPP_DATA_DIR="${CRYPTOPP_DATA_DIR}") endif() #============================================================================ @@ -78,26 +92,31 @@ set(cryptopp_SOURCES ${cryptopp_SOURCES} ) -if(MINGW) +if(WIN32) list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/winpipes.cpp) endif() +if(MSVC AND NOT DISABLE_ASM) + enable_language(ASM_MASM) + if(BITS EQUAL 32) + set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /nologo /D_M_X86 /W3 /Cx /Zi /safeseh") + else() + set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /nologo /D_M_X64 /W3 /Cx /Zi") + list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64dll.asm) + list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/x64masm.asm) + endif() + list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/rdrand.asm) +endif() + #============================================================================ # Compile targets #============================================================================ -add_library(cryptopp-object OBJECT ${cryptopp_SOURCES}) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - # Enables -fPIC on all 64-bit platforms - set_target_properties(cryptopp-object PROPERTIES POSITION_INDEPENDENT_CODE TRUE) +if(${CMAKE_VERSION} VERSION_GREATER 2.8.8) + include("cmake/cryptopp-compile-targets-2.8.8.cmake") +else() + include("cmake/cryptopp-compile-targets.cmake") endif() -add_library(cryptopp-static STATIC $) -add_library(cryptopp-shared SHARED $) - -target_include_directories(cryptopp-shared PUBLIC $ $) -target_include_directories(cryptopp-static PUBLIC $ $) - if(NOT MSVC) set(COMPAT_VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR}) @@ -127,9 +146,7 @@ target_link_libraries(cryptopp-shared ${CMAKE_THREAD_LIBS_INIT}) #============================================================================ enable_testing() if(BUILD_TESTING) - add_library(cryptest-object OBJECT ${cryptopp_SOURCES_TEST}) - - add_executable(cryptest $) + add_executable(cryptest ${cryptopp_SOURCES_TEST}) target_link_libraries(cryptest cryptopp-static) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/TestData DESTINATION ${PROJECT_BINARY_DIR}) @@ -175,9 +192,9 @@ install(TARGETS cryptopp-static EXPORT ${export_name} DESTINATION ${CMAKE_INSTAL install(FILES ${cryptopp_HEADERS} DESTINATION include/cryptopp) # CMake Package -include(CMakePackageConfigHelpers) -write_basic_package_version_file("${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake" VERSION ${cryptopp_VERSION_MAJOR}.${cryptopp_VERSION_MINOR}.${cryptopp_VERSION_PATCH} COMPATIBILITY SameMajorVersion) -install(FILES cryptopp-config.cmake ${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake DESTINATION "lib/cmake/cryptopp") +set(CVF_VERSION "${cryptopp_VERSION}") +configure_file(cmake/cryptopp-config-version.in ${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake) +install(FILES cmake/cryptopp-config.cmake ${PROJECT_BINARY_DIR}/cryptopp-config-version.cmake DESTINATION "lib/cmake/cryptopp") install(EXPORT ${export_name} DESTINATION "lib/cmake/cryptopp") # Tests @@ -187,7 +204,6 @@ if(BUILD_TESTING) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/TestVectors DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cryptopp) endif() - # Documentation if(BUILD_DOCUMENTATION) install(DIRECTORY "${out_source_DOCS_DIR}" DESTINATION ${CMAKE_INSTALL_DOCDIR}) diff --git a/Filelist.txt b/Filelist.txt index e55b1041..d3cab7b4 100644 --- a/Filelist.txt +++ b/Filelist.txt @@ -304,7 +304,10 @@ Readme.txt Install.txt Filelist.txt CMakeLists.txt -cryptopp-config.cmake +cmake/cryptopp-compile-targets.cmake +cmake/cryptopp-compile-targets-2.8.8.cmake +cmake/cryptopp-config.cmake +cmake/cryptopp-config-version.in TestData/3desval.dat TestData/3wayval.dat TestData/camellia.dat diff --git a/GNUmakefile b/GNUmakefile index e80ab1ec..0c62567f 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -446,11 +446,14 @@ endif .PHONY: distclean distclean: clean -$(RM) adhoc.cpp adhoc.cpp.copied GNUmakefile.deps benchmarks.html cryptest.txt cryptest-*.txt - -$(RM) CMakeCache.txt Makefile CTestTestfile.cmake cmake_install.cmake cryptopp-config-version.cmake + -$(RM) CMakeCache.txt install_manifest.txt Makefile *.cmake -$(RM) *.o *.ii *.s *~ ifneq ($(wildcard CMakeFiles/),) -$(RM) -r CMakeFiles/ endif +ifneq ($(wildcard Testing/),) + -$(RM) -r Testing/ +endif ifneq ($(wildcard cryptopp$(LIB_VER)\.*),) -$(RM) cryptopp$(LIB_VER)\.* endif @@ -560,7 +563,7 @@ dlltest.exe: cryptopp.dll $(DLLTESTOBJS) $(CXX) -o $@ $(CXXFLAGS) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS) # This recipe prepares the distro files -TEXT_FILES := *.h *.cpp adhoc.cpp.proto License.txt Readme.txt Install.txt Filelist.txt CMakeLists.txt config.recommend Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcproj *.dsw *.dsp cryptopp.rc TestVectors/*.txt TestData/*.dat +TEXT_FILES := *.h *.cpp adhoc.cpp.proto License.txt Readme.txt Install.txt Filelist.txt CMakeLists.txt cmake/* config.recommend Doxyfile cryptest* cryptlib* dlltest* cryptdll* *.sln *.vcproj *.dsw *.dsp cryptopp.rc TestVectors/*.txt TestData/*.dat EXEC_FILES := GNUmakefile GNUmakefile-cross TestData/ TestVectors/ ifeq ($(wildcard Filelist.txt),Filelist.txt) diff --git a/cmake/cryptopp-compile-targets-2.8.8.cmake b/cmake/cryptopp-compile-targets-2.8.8.cmake new file mode 100644 index 00000000..6e83c15c --- /dev/null +++ b/cmake/cryptopp-compile-targets-2.8.8.cmake @@ -0,0 +1,9 @@ +add_library(cryptopp-object OBJECT ${cryptopp_SOURCES}) + +set_target_properties(cryptopp-object PROPERTIES POSITION_INDEPENDENT_CODE ${cryptopp_POSITION_INDEPENDENT_CODE}) + +add_library(cryptopp-static STATIC $) +add_library(cryptopp-shared SHARED $) + +target_include_directories(cryptopp-shared PUBLIC $ $) +target_include_directories(cryptopp-static PUBLIC $ $) diff --git a/cmake/cryptopp-compile-targets.cmake b/cmake/cryptopp-compile-targets.cmake new file mode 100644 index 00000000..d6500994 --- /dev/null +++ b/cmake/cryptopp-compile-targets.cmake @@ -0,0 +1,5 @@ +add_library(cryptopp-static STATIC ${cryptopp_SOURCES}) +add_library(cryptopp-shared SHARED ${cryptopp_SOURCES}) + +set_target_properties(cryptopp-static PROPERTIES POSITION_INDEPENDENT_CODE ${cryptopp_POSITION_INDEPENDENT_CODE}) +set_target_properties(cryptopp-shared PROPERTIES POSITION_INDEPENDENT_CODE ${cryptopp_POSITION_INDEPENDENT_CODE}) diff --git a/cmake/cryptopp-config-version.in b/cmake/cryptopp-config-version.in new file mode 100644 index 00000000..542d576e --- /dev/null +++ b/cmake/cryptopp-config-version.in @@ -0,0 +1,45 @@ +# This is a basic version file for the Config-mode of find_package(). +# It is used by write_basic_package_version_file() as input file for configure_file() +# to create a version-file which can be installed along a config.cmake file. +# +# The created file sets PACKAGE_VERSION_EXACT if the current version string and +# the requested version string are exactly the same and it sets +# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, +# but only if the requested major version is the same as the current one. +# The variable CVF_VERSION must be set before calling configure_file(). + +set(PACKAGE_VERSION "@CVF_VERSION@") + +if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + + if("@CVF_VERSION@" MATCHES "^([0-9]+)\\.") + set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") + else() + set(CVF_VERSION_MAJOR "@CVF_VERSION@") + endif() + + if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() + + +# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "") + return() +endif() + +# check that the installed version has the same 32/64bit-ness as the one which is currently searching: +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@CMAKE_SIZEOF_VOID_P@") + math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/cryptopp-config.cmake b/cmake/cryptopp-config.cmake similarity index 100% rename from cryptopp-config.cmake rename to cmake/cryptopp-config.cmake