CMakeLists.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # The CMakeLists.txt shipped with cryptopp pollutes our option list and installation list,
  2. # so we made our own one. This is basically a trimmed down version of the shipped CMakeLists.txt
  3. # The differences are:
  4. # - removed support for legacy CMake versions
  5. # - removed support for 32-bit
  6. # - removed -march=native flag
  7. # - removed rdrand module.asm as a workaround for an issue (see below)
  8. # - added prefix "CRYPTOPP_" to all option names
  9. # - disabled testing
  10. # - disabled installation
  11. # - disabled documentation
  12. # - configured to build a static library only
  13. # - adds include directories to the library target
  14. include(TestBigEndian)
  15. include(CheckCXXCompilerFlag)
  16. #============================================================================
  17. # Settable options
  18. #============================================================================
  19. option(CRYPTOPP_DISABLE_ASM "Disable ASM" OFF)
  20. option(CRYPTOPP_DISABLE_SSSE3 "Disable SSSE3" OFF)
  21. option(CRYPTOPP_DISABLE_AESNI "Disable AES-NI" OFF)
  22. option(CRYPTOPP_DISABLE_CXXFLAGS_OPTIMIZATIONS "Disable CXXFLAGS optimizations" OFF)
  23. #============================================================================
  24. # Internal compiler options
  25. #============================================================================
  26. # Only set when cross-compiling, http://www.vtk.org/Wiki/CMake_Cross_Compiling
  27. if (NOT (CMAKE_SYSTEM_VERSION AND CMAKE_SYSTEM_PROCESSOR))
  28. set(CRYPTOPP_CROSS_COMPILE 1)
  29. else()
  30. set(CRYPTOPP_CROSS_COMPILE 0)
  31. endif()
  32. # Don't use RPATH's. The resulting binary could fail a security audit.
  33. if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
  34. set(CMAKE_MACOSX_RPATH 0)
  35. endif()
  36. if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
  37. add_definitions(-wd68 -wd186 -wd279 -wd327 -wd161 -wd3180)
  38. endif()
  39. # Endianness
  40. TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
  41. if(IS_BIG_ENDIAN)
  42. add_definitions(-DIS_BIG_ENDIAN)
  43. endif()
  44. if(CRYPTOPP_DISABLE_ASM)
  45. add_definitions(-DCRYPTOPP_DISABLE_ASM)
  46. endif()
  47. if(CRYPTOPP_DISABLE_SSSE3)
  48. add_definitions(-DCRYPTOPP_DISABLE_SSSE3)
  49. endif()
  50. if(CRYPTOPP_DISABLE_AESNI)
  51. add_definitions(-DCRYPTOPP_DISABLE_AESNI)
  52. endif()
  53. # We need the output 'uname -s' for Unix and Linux system detection
  54. if (NOT CRYPTOPP_CROSS_COMPILE)
  55. set (UNAME_CMD "uname")
  56. set (UNAME_ARG "-s")
  57. execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG}
  58. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  59. RESULT_VARIABLE UNAME_RESULT
  60. OUTPUT_VARIABLE UNAME_SYSTEM)
  61. string(REGEX REPLACE "\n$" "" UNAME_SYSTEM "${UNAME_SYSTEM}")
  62. endif()
  63. # We need the output 'uname -m' for Unix and Linux platform detection
  64. if (NOT CRYPTOPP_CROSS_COMPILE)
  65. set (UNAME_CMD "uname")
  66. set (UNAME_ARG "-m")
  67. execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG}
  68. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  69. RESULT_VARIABLE UNAME_RESULT
  70. OUTPUT_VARIABLE UNAME_MACHINE)
  71. string(REGEX REPLACE "\n$" "" UNAME_MACHINE "${UNAME_MACHINE}")
  72. endif()
  73. if(WINDOWS_STORE OR WINDOWS_PHONE)
  74. if("${CMAKE_SYSTEM_VERSION}" MATCHES "10\\.0.*")
  75. SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_WIN32_WINNT=0x0A00\"" )
  76. endif()
  77. SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"winapifamily.h\"" )
  78. endif()
  79. # Enable PIC for all targets except Windows and 32-bit x86.
  80. # Avoid on 32-bit x86 due to register pressures.
  81. if ((NOT CRYPTOPP_CROSS_COMPILE) AND (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE)))
  82. # Use Regex; match i386, i486, i586 and i686
  83. if (NOT (${UNAME_MACHINE} MATCHES "i.86"))
  84. SET(CMAKE_POSITION_INDEPENDENT_CODE 1)
  85. endif()
  86. endif()
  87. # Link is driven through the compiler, but CXXFLAGS are not used. Also see
  88. # http://public.kitware.com/pipermail/cmake/2003-June/003967.html
  89. if (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE))
  90. SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_FLAGS}")
  91. endif()
  92. #============================================================================
  93. # Sources & headers
  94. #============================================================================
  95. # Library headers
  96. file(GLOB cryptopp_HEADERS cryptopp/*.h)
  97. # Library sources. You can use the GNUmakefile to generate the list: `make sources`.
  98. file(GLOB cryptopp_SOURCES cryptopp/*.cpp)
  99. list(REMOVE_ITEM cryptopp_SOURCES
  100. # These are removed in the original CMakeLists.txt
  101. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/pch.cpp
  102. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/simple.cpp
  103. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/winpipes.cpp
  104. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/cryptlib_bds.cpp
  105. ${cryptopp_SOURCES_TEST}
  106. )
  107. if(MINGW OR WIN32)
  108. list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/winpipes.cpp)
  109. endif()
  110. if(MSVC AND NOT CRYPTOPP_DISABLE_ASM)
  111. if(${CMAKE_GENERATOR} MATCHES ".*ARM")
  112. message(STATUS "Disabling ASM because ARM is specified as target platform.")
  113. else()
  114. # Note that we removed rdrand.asm. This is a workaround for the issue that rdrand.asm cannnot compiled properly
  115. # on MSVC. Because there is also a rdrand.S file in the submodule, CMake will specify the target path for
  116. # rdrand.asm as "/crytopp.dir/{Debug|Release}/cryptopp/rdrand.asm.obj". The additional target folder "cryptopp"
  117. # is specified because the file rdrand.asm is in the source folder "cryptopp". But MSVC assembler can't build
  118. # target file to an non-existing folder("cryptopp").
  119. list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64dll.asm)
  120. list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64masm.asm)
  121. # list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/rdrand.asm)
  122. set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
  123. set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
  124. # set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
  125. enable_language(ASM_MASM)
  126. endif()
  127. endif()
  128. #============================================================================
  129. # Compile targets
  130. #============================================================================
  131. add_library(cryptopp STATIC ${cryptopp_SOURCES})
  132. target_include_directories(cryptopp INTERFACE .)
  133. #============================================================================
  134. # Third-party libraries
  135. #============================================================================
  136. if(WIN32)
  137. target_link_libraries(cryptopp PRIVATE ws2_32)
  138. endif()
  139. find_package(Threads)
  140. target_link_libraries(cryptopp PRIVATE ${CMAKE_THREAD_LIBS_INIT})