CMakeLists.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. cmake_minimum_required(VERSION 3.1)
  2. project(BEE2 C)
  3. set(BEE2_VERSION_MAJOR "2")
  4. set(BEE2_VERSION_MINOR "1")
  5. set(BEE2_VERSION_PATCH "5")
  6. set(BEE2_VERSION
  7. "${BEE2_VERSION_MAJOR}.${BEE2_VERSION_MINOR}.${BEE2_VERSION_PATCH}")
  8. option(BUILD_SHARED_LIBS "Build shared libraries." ON)
  9. option(BUILD_PIC "Build position independent code." ON)
  10. option(BUILD_FAST "Build with the SAFE_FAST directive." OFF)
  11. option(BUILD_CMD "Build cmds." ON)
  12. option(BUILD_TESTS "Build tests." ON)
  13. option(BUILD_DOC "Build documentation (doxygen required)." OFF)
  14. option(INSTALL_HEADERS "Install headers." ON)
  15. if(CMAKE_BUILD_TYPE)
  16. set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
  17. CACHE STRING "Choose the type of build: \
  18. Release Debug Coverage ASan ASanDbg MemSan MemSanDbg Check"
  19. FORCE)
  20. else()
  21. set(CMAKE_BUILD_TYPE Release
  22. CACHE STRING
  23. "Choose the type of build: \
  24. Release Debug Coverage ASan ASanDbg MemSan MemSanDbg Check"
  25. FORCE)
  26. endif()
  27. message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
  28. message(STATUS "Compiler: ${CMAKE_C_COMPILER_ID}")
  29. string(COMPARE EQUAL "GNU" "${CMAKE_C_COMPILER_ID}" CMAKE_COMPILER_IS_GNUCC)
  30. string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
  31. string(COMPARE EQUAL "MSVC" "${CMAKE_C_COMPILER_ID}" CMAKE_COMPILER_IS_MSVC)
  32. if (BASH_PLATFORM)
  33. if(BASH_PLATFORM STREQUAL "BASH_32")
  34. set(BASH_32 ON BOOL)
  35. add_definitions(-DBASH_32)
  36. elseif(BASH_PLATFORM STREQUAL "BASH_SSE2")
  37. set(BASH_SSE2 ON BOOL)
  38. add_definitions(-DBASH_SSE2)
  39. elseif(BASH_PLATFORM STREQUAL "BASH_AVX2")
  40. set(BASH_AVX2 ON BOOL)
  41. add_definitions(-DBASH_AVX2)
  42. elseif(BASH_PLATFORM STREQUAL "BASH_AVX512")
  43. set(BASH_AVX512 ON BOOL)
  44. add_definitions(-DBASH_AVX512)
  45. elseif(BASH_PLATFORM STREQUAL "BASH_NEON")
  46. set(BASH_NEON ON BOOL)
  47. add_definitions(-DBASH_NEON)
  48. elseif(NOT BASH_PLATFORM STREQUAL "BASH_64")
  49. message(WARNING "Unknown BASH_PLATFORM (${BASH_PLATFORM}). \
  50. This option will be ignored")
  51. unset(BASH_PLATFORM CACHE)
  52. endif()
  53. endif()
  54. if (BASH_PLATFORM)
  55. message(STATUS "Requested BASH_PLATFORM: ${BASH_PLATFORM}")
  56. endif()
  57. # Lists of warnings and command-line flags:
  58. # * https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  59. # * https://clang.llvm.org/docs/ClangCommandLineReference.html
  60. # * https://clang.llvm.org/docs/DiagnosticsReference.html
  61. set(CMAKE_C_WARNINGS "-Wall -Wextra -W -Wdeclaration-after-statement \
  62. -Wwrite-strings -Wno-parentheses -Wno-unused-parameter -Wno-strict-aliasing \
  63. -Wno-xor-used-as-pow")
  64. if(CMAKE_COMPILER_IS_GNUCC)
  65. set(CMAKE_C_WARNINGS "${CMAKE_C_WARNINGS} -Wno-maybe-uninitialized")
  66. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARNINGS}")
  67. if(BASH_SSE2)
  68. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
  69. elseif(BASH_AVX2)
  70. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
  71. elseif(BASH_AVX512)
  72. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f \
  73. -fno-asynchronous-unwind-tables")
  74. elseif(BASH_NEON)
  75. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  76. endif()
  77. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 \
  78. -fno-strict-aliasing")
  79. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3")
  80. set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_COVERAGE} -O0 -g3 -coverage")
  81. set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -fsanitize=address \
  82. -fno-common -O3 -fno-strict-aliasing")
  83. set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -fsanitize=address \
  84. -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  85. set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS_CHECK} -Werror -O1 \
  86. -Wcast-qual -fanalyzer")
  87. endif(CMAKE_COMPILER_IS_GNUCC)
  88. if(CMAKE_COMPILER_IS_CLANG)
  89. set(CMAKE_C_WARNINGS "${CMAKE_C_WARNINGS} -Wno-parentheses-equality \
  90. -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses")
  91. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARNINGS}")
  92. if(BASH_SSE2)
  93. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
  94. elseif(BASH_AVX2)
  95. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
  96. elseif(BASH_AVX512)
  97. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
  98. -mavx512f -fno-asynchronous-unwind-tables")
  99. elseif(BASH_NEON)
  100. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  101. endif()
  102. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 \
  103. -fno-strict-aliasing")
  104. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3")
  105. set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_COVERAGE} -O0 -g3 -coverage")
  106. set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -fsanitize=address \
  107. -fno-common -fsanitize=undefined -fno-sanitize-recover -O3 \
  108. -fno-strict-aliasing")
  109. set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -fsanitize=address \
  110. -fno-common -fsanitize=undefined -fno-sanitize-recover -O1 -g3 \
  111. -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  112. set(CMAKE_C_FLAGS_MEMSAN "${CMAKE_C_FLAGS_MEMSAN} -fsanitize=memory -O3 \
  113. -fno-strict-aliasing")
  114. set(CMAKE_C_FLAGS_MEMSANDBG "${CMAKE_C_FLAGS_MEMSANDBG} -fsanitize=memory \
  115. -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls \
  116. -fsanitize-memory-track-origins=2")
  117. set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS_CHECK} -Werror -O1 -Wcast-qual")
  118. endif(CMAKE_COMPILER_IS_CLANG)
  119. if(CMAKE_COMPILER_IS_MSVC)
  120. # disable security warnings for sprintf()
  121. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS")
  122. if(BASH_SSE2)
  123. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
  124. elseif(BASH_AVX2)
  125. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2")
  126. elseif(BASH_AVX512)
  127. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX512")
  128. endif()
  129. endif(CMAKE_COMPILER_IS_MSVC)
  130. if(BUILD_FAST)
  131. add_definitions(-DSAFE_FAST)
  132. endif()
  133. if(NOT LIB_INSTALL_DIR)
  134. set(LIB_INSTALL_DIR lib)
  135. endif()
  136. if(NOT BIN_INSTALL_DIR)
  137. set(BIN_INSTALL_DIR bin)
  138. endif()
  139. include_directories(include/)
  140. include_directories(src/)
  141. add_subdirectory(include)
  142. add_subdirectory(src)
  143. if(BUILD_CMD)
  144. add_subdirectory(cmd)
  145. endif()
  146. if(BUILD_TESTS)
  147. enable_testing()
  148. add_subdirectory(test)
  149. endif()
  150. if(BUILD_DOC)
  151. add_subdirectory(doc)
  152. endif()