CMakeLists.txt 6.4 KB

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