CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. cmake_minimum_required(VERSION 2.6)
  2. project(BEE2EVP C)
  3. set(BEE2EVP_VERSION_MAJOR "1")
  4. set(BEE2EVP_VERSION_MINOR "0")
  5. set(BEE2EVP_VERSION_PATCH "4")
  6. set(BEE2EVP_VERSION "${BEE2EVP_VERSION_MAJOR}.${BEE2EVP_VERSION_MINOR}.${BEE2EVP_VERSION_PATCH}")
  7. option(BUILD_DOC "Build documentation (doxygen required)." OFF)
  8. option(INSTALL_HEADERS "Install headers." ON)
  9. string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
  10. if(CMAKE_BUILD_TYPE)
  11. set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
  12. CACHE STRING "Choose the type of build: Release Debug Coverage ASan ASanDbg MemSan MemSanDbg Check"
  13. FORCE)
  14. else()
  15. set(CMAKE_BUILD_TYPE Release
  16. CACHE STRING "Choose the type of build: Release Debug Coverage ASan ASanDbg MemSan MemSanDbg Check"
  17. FORCE)
  18. endif()
  19. message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
  20. if(CMAKE_COMPILER_IS_GNUCC)
  21. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wlogical-op -Wno-parentheses -Wno-unused-parameter -Wno-strict-aliasing")
  22. set(CMAKE_C_FLAGS_RELEASE "-O2")
  23. set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
  24. set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
  25. set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3")
  26. set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
  27. set(CMAKE_C_FLAGS_CHECK "-Werror -O1 -Wcast-qual")
  28. endif(CMAKE_COMPILER_IS_GNUCC)
  29. if(CMAKE_COMPILER_IS_CLANG)
  30. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith -Wno-parentheses -Wno-unused-parameter -Wno-strict-aliasing")
  31. set(CMAKE_C_FLAGS_RELEASE "-O2")
  32. set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
  33. set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
  34. set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O3")
  35. set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  36. set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3")
  37. set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
  38. set(CMAKE_C_FLAGS_CHECK "-Werror -O1")
  39. endif(CMAKE_COMPILER_IS_CLANG)
  40. if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
  41. if(CMAKE_COMPILER_IS_GNUCC)
  42. set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
  43. endif(CMAKE_COMPILER_IS_GNUCC)
  44. if(CMAKE_COMPILER_IS_CLANG)
  45. set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
  46. endif(CMAKE_COMPILER_IS_CLANG)
  47. endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
  48. if(NOT LIB_INSTALL_DIR)
  49. set(LIB_INSTALL_DIR lib)
  50. endif()
  51. if(NOT BIN_INSTALL_DIR)
  52. set(BIN_INSTALL_DIR bin)
  53. endif()
  54. find_package(PkgConfig REQUIRED)
  55. pkg_search_module(OPENSSL openssl>=1.1.0)
  56. if(NOT OPENSSL_FOUND)
  57. message(WARNING
  58. "Can't find the OpenSSL package. Suppose that OpenSSL exists...")
  59. set(OPENSSL_INCLUDE_DIR
  60. /usr/local/include/
  61. )
  62. set(OPENSSL_LIBRARY_DIRS
  63. /usr/local/lib/
  64. )
  65. set(OPENSSL_LIBRARIES
  66. /usr/local/lib/libcrypto.so /usr/local/lib/libssl.so
  67. )
  68. endif()
  69. if(NOT BEE2_INCLUDE_DIR)
  70. set(BEE2_INCLUDE_DIR
  71. /usr/local/share/
  72. )
  73. endif()
  74. include_directories(
  75. include/
  76. src/
  77. ${BEE2_INCLUDE_DIR}
  78. ${OPENSSL_INCLUDE_DIR}
  79. )
  80. link_directories(${OPENSSL_LIBRARY_DIRS})
  81. add_subdirectory(include)
  82. set(src
  83. src/bee2evp.c
  84. src/bash_md.c
  85. src/belt_ameth.c
  86. src/belt_cipher.c
  87. src/belt_md.c
  88. src/belt_pbkdf.c
  89. src/belt_pmeth.c
  90. src/bign_ameth.c
  91. src/bign_asn1.c
  92. src/bign_pmeth.c
  93. )
  94. set(libs bee2 ${OPENSSL_LIBRARIES})
  95. add_library(bee2evp SHARED ${src})
  96. target_link_libraries(bee2evp ${libs})
  97. # uncomment next lines to keep track of bee2evp.so with version numbers
  98. # set_target_properties(bee2evp PROPERTIES
  99. # VERSION ${BEE2EVP_VERSION_MAJOR}.${BEE2EVP_VERSION_MINOR}.${BEE2EVP_VERSION_PATCH}
  100. # SOVERSION 1.0)
  101. install(TARGETS bee2evp
  102. DESTINATION ${LIB_INSTALL_DIR}
  103. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  104. if(BUILD_DOC)
  105. add_subdirectory(doc)
  106. endif()