You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

133 lines
5.0 KiB

  1. ############################################################################
  2. # CMakeLists.txt
  3. #
  4. # Released under the MIT License. See LICENSE.txt for license information.
  5. #
  6. ############################################################################
  7. if(MSVC)
  8. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  9. endif()
  10. set(DECAF_HEADER_FILES
  11. include/constant_time.h
  12. include/field.h
  13. include/keccak_internal.h
  14. include/portable_endian.h
  15. include/word.h
  16. )
  17. set(DECAF_SOURCE_FILES_C
  18. utils.c
  19. shake.c
  20. sha512.c
  21. spongerng.c
  22. )
  23. # default target arch is arch_32 which shall be generic enough to compile mostly on anything
  24. # target arch dirs:
  25. # global one to get the include/arch_intrinsics.h
  26. # availables: arch_32, arch_arm_32, arch_neon, arch_ref64, arch_x86_64
  27. set(TARGET_ARCH_DIR arch_32)
  28. # specific to p25519, to get f_impl.c/h in p25519
  29. #availables: arch_32, arch_ref64, arch_x86_64
  30. set(TARGET_ARCH_DIR_P25519 arch_32)
  31. # specific to p448, to get f_impl.c/h in p448
  32. # availables: arch_32, arch_arm_32, arch_neon, arch_ref64, arch_x86_64
  33. set(TARGET_ARCH_DIR_P448 arch_32)
  34. if(MSVC)# On MSVC Windows, Processor is always AMD64 on both platforms (x86/x64)
  35. set(MSVC_ARCH ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})# ${MSVC_ARCH} MATCHES "X64"
  36. else()
  37. set(MSVC_ARCH ${CMAKE_SYSTEM_PROCESSOR})# just to have a value
  38. endif()
  39. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" AND NOT MSVC)#Decaf doesn't support 64bits on MSVC yet
  40. message("Target architecture is x86_64")
  41. set(TARGET_ARCH_DIR arch_x86_64)
  42. set(TARGET_ARCH_DIR_P25519 arch_x86_64)
  43. set(TARGET_ARCH_DIR_P448 arch_x86_64)
  44. elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arch64") # shall be arm64 bits, stick to ref64.
  45. message("Target architecture is 64 bits general purpose(arm64 shall use this)")
  46. set(TARGET_ARCH_DIR arch_ref64)
  47. set(TARGET_ARCH_DIR_P25519 arch_ref64)
  48. set(TARGET_ARCH_DIR_P448 arch_ref64)
  49. elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") # is an arm 32 bits
  50. if (NOT ${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi") # arm <= 5.0 does not support instructions from the lib, keep arch_32
  51. if(${ANDROID_ARM_NEON})
  52. message("Target architecture is arm32 NEON")
  53. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") # build with neon flag
  54. set(TARGET_ARCH_DIR arch_neon)
  55. set(TARGET_ARCH_DIR_P25519 arch_32) # nothing specific for neon on p25519
  56. set(TARGET_ARCH_DIR_P448 arch_neon)
  57. else(${ANDROID_ARM_NEON})
  58. message("Target architecture is arm32 no NEON")
  59. set(TARGET_ARCH_DIR arch_arm_32)
  60. set(TARGET_ARCH_DIR_P25519 arch_32) # nothing specific for arch_arm on p25519
  61. set(TARGET_ARCH_DIR_P448 arch_arm_32)
  62. endif(${ANDROID_ARM_NEON})
  63. endif (NOT ${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi")
  64. else() # nothing picked yet, stick to the
  65. message("Target architecture is general purpose 32bits")
  66. endif()
  67. include_directories(
  68. ${PROJECT_SOURCE_DIR}/src/include/${TARGET_ARCH_DIR}
  69. )
  70. set(DECAF_SOURCE_FILES_CXX
  71. )
  72. add_subdirectory(curve25519)
  73. add_subdirectory(ed448goldilocks)
  74. add_subdirectory(p25519)
  75. add_subdirectory(p448)
  76. add_subdirectory(generator)
  77. if(ENABLE_STATIC)
  78. add_library(decaf-static STATIC ${DECAF_HEADER_FILES} ${DECAF_SOURCE_FILES_C} ${DECAF_SOURCE_FILES_CXX} $<TARGET_OBJECTS:p25519> $<TARGET_OBJECTS:p448> $<TARGET_OBJECTS:CURVE25519> $<TARGET_OBJECTS:CURVE448>)
  79. add_dependencies(decaf-static generatedCode)
  80. set_target_properties(decaf-static PROPERTIES OUTPUT_NAME decaf)
  81. target_include_directories(decaf-static INTERFACE $<INSTALL_INTERFACE:include/decaf>)
  82. target_link_libraries(decaf-static INTERFACE)
  83. endif()
  84. if(ENABLE_SHARED)
  85. add_library(decaf SHARED ${DECAF_HEADER_FILES} ${DECAF_SOURCE_FILES_C} ${DECAF_SOURCE_FILES_CXX} $<TARGET_OBJECTS:p25519> $<TARGET_OBJECTS:p448> $<TARGET_OBJECTS:CURVE25519> $<TARGET_OBJECTS:CURVE448>)
  86. add_dependencies(decaf generatedCode)
  87. set_target_properties(decaf PROPERTIES VERSION ${DECAF_SO_VERSION})
  88. target_include_directories(decaf INTERFACE $<INSTALL_INTERFACE:include/decaf>)
  89. target_link_libraries(decaf PRIVATE)
  90. if(MSVC)
  91. if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  92. install(FILES $<TARGET_PDB_FILE:decaf>
  93. DESTINATION ${CMAKE_INSTALL_BINDIR}
  94. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
  95. )
  96. endif()
  97. endif()
  98. endif()
  99. if(ENABLE_STATIC)
  100. install(TARGETS decaf-static EXPORT ${EXPORT_TARGETS_NAME}Targets
  101. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  102. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  103. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  104. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
  105. )
  106. endif()
  107. if(ENABLE_SHARED)
  108. install(TARGETS decaf EXPORT ${EXPORT_TARGETS_NAME}Targets
  109. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  110. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  111. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  112. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
  113. )
  114. endif()
  115. install(DIRECTORY ${GSOURCE_PATH}/include/
  116. DESTINATION include/decaf
  117. FILES_MATCHING PATTERN "*.h*"
  118. PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  119. )