CMakeLists.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. if(MSVC)
  40. # Disable C4390: empty controlled statement found: is this the intent?
  41. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4390")
  42. endif()
  43. # Endianness
  44. TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
  45. if(IS_BIG_ENDIAN)
  46. add_definitions(-DIS_BIG_ENDIAN)
  47. endif()
  48. if(CRYPTOPP_DISABLE_ASM)
  49. add_definitions(-DCRYPTOPP_DISABLE_ASM)
  50. endif()
  51. if(CRYPTOPP_DISABLE_SSSE3)
  52. add_definitions(-DCRYPTOPP_DISABLE_SSSE3)
  53. endif()
  54. if(CRYPTOPP_DISABLE_AESNI)
  55. add_definitions(-DCRYPTOPP_DISABLE_AESNI)
  56. endif()
  57. # We need the output 'uname -s' for Unix and Linux system detection
  58. if (NOT CRYPTOPP_CROSS_COMPILE)
  59. set (UNAME_CMD "uname")
  60. set (UNAME_ARG "-s")
  61. execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG}
  62. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  63. RESULT_VARIABLE UNAME_RESULT
  64. OUTPUT_VARIABLE UNAME_SYSTEM)
  65. string(REGEX REPLACE "\n$" "" UNAME_SYSTEM "${UNAME_SYSTEM}")
  66. endif()
  67. # We need the output 'uname -m' for Unix and Linux platform detection
  68. if (NOT CRYPTOPP_CROSS_COMPILE)
  69. set (UNAME_CMD "uname")
  70. set (UNAME_ARG "-m")
  71. execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG}
  72. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  73. RESULT_VARIABLE UNAME_RESULT
  74. OUTPUT_VARIABLE UNAME_MACHINE)
  75. string(REGEX REPLACE "\n$" "" UNAME_MACHINE "${UNAME_MACHINE}")
  76. endif()
  77. if(WINDOWS_STORE OR WINDOWS_PHONE)
  78. if("${CMAKE_SYSTEM_VERSION}" MATCHES "10\\.0.*")
  79. SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D\"_WIN32_WINNT=0x0A00\"" )
  80. endif()
  81. SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FI\"winapifamily.h\"" )
  82. endif()
  83. # Enable PIC for all targets except Windows and 32-bit x86.
  84. # Avoid on 32-bit x86 due to register pressures.
  85. if ((NOT CRYPTOPP_CROSS_COMPILE) AND (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE)))
  86. # Use Regex; match i386, i486, i586 and i686
  87. if (NOT (${UNAME_MACHINE} MATCHES "i.86"))
  88. SET(CMAKE_POSITION_INDEPENDENT_CODE 1)
  89. endif()
  90. endif()
  91. # Link is driven through the compiler, but CXXFLAGS are not used. Also see
  92. # http://public.kitware.com/pipermail/cmake/2003-June/003967.html
  93. if (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE))
  94. SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_FLAGS}")
  95. endif()
  96. #============================================================================
  97. # Sources & headers
  98. #============================================================================
  99. # Library headers
  100. file(GLOB cryptopp_HEADERS cryptopp/*.h)
  101. # Library sources. You can use the GNUmakefile to generate the list: `make sources`.
  102. file(GLOB cryptopp_SOURCES cryptopp/*.cpp)
  103. list(REMOVE_ITEM cryptopp_SOURCES
  104. # These are removed in the original CMakeLists.txt
  105. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/pch.cpp
  106. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/simple.cpp
  107. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/winpipes.cpp
  108. ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/cryptlib_bds.cpp
  109. ${cryptopp_SOURCES_TEST}
  110. )
  111. if(MINGW OR WIN32)
  112. list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/winpipes.cpp)
  113. endif()
  114. if(MSVC AND NOT CRYPTOPP_DISABLE_ASM)
  115. if(${CMAKE_GENERATOR} MATCHES ".*ARM")
  116. message(STATUS "Disabling ASM because ARM is specified as target platform.")
  117. else()
  118. # Note that we removed rdrand.asm. This is a workaround for the issue that rdrand.asm cannnot compiled properly
  119. # on MSVC. Because there is also a rdrand.S file in the submodule, CMake will specify the target path for
  120. # rdrand.asm as "/crytopp.dir/{Debug|Release}/cryptopp/rdrand.asm.obj". The additional target folder "cryptopp"
  121. # is specified because the file rdrand.asm is in the source folder "cryptopp". But MSVC assembler can't build
  122. # target file to an non-existing folder("cryptopp").
  123. list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64dll.asm)
  124. list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64masm.asm)
  125. # list(APPEND cryptopp_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/rdrand.asm)
  126. set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64dll.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
  127. set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/x64masm.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
  128. # set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/rdrand.asm PROPERTIES COMPILE_FLAGS "/D_M_X64")
  129. enable_language(ASM_MASM)
  130. endif()
  131. endif()
  132. #============================================================================
  133. # Compile targets
  134. #============================================================================
  135. add_library(cryptopp STATIC ${cryptopp_SOURCES})
  136. target_include_directories(cryptopp INTERFACE .)
  137. #============================================================================
  138. # Third-party libraries
  139. #============================================================================
  140. if(WIN32)
  141. target_link_libraries(cryptopp PRIVATE ws2_32)
  142. endif()
  143. find_package(Threads)
  144. target_link_libraries(cryptopp PRIVATE ${CMAKE_THREAD_LIBS_INIT})