CMakeLists.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "1")
  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
  18. "Choose the type of build: 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: Release Debug Coverage ASan ASanDbg MemSan MemSanDbg Check"
  24. FORCE)
  25. endif()
  26. message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
  27. message(STATUS "Compiler: ${CMAKE_C_COMPILER_ID}")
  28. string(COMPARE EQUAL "GNU" CMAKE_COMPILER_IS_GNUCC "${CMAKE_C_COMPILER_ID}")
  29. string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
  30. string(COMPARE EQUAL "MSVC" CMAKE_COMPILER_IS_MSVC "${CMAKE_C_COMPILER_ID}")
  31. if (BASH_PLATFORM)
  32. if(BASH_PLATFORM STREQUAL "BASH_32")
  33. set(BASH_32 ON BOOL)
  34. add_definitions(-DBASH_32)
  35. elseif(BASH_PLATFORM STREQUAL "BASH_SSE2")
  36. set(BASH_SSE2 ON BOOL)
  37. add_definitions(-DBASH_SSE2)
  38. elseif(BASH_PLATFORM STREQUAL "BASH_AVX2")
  39. set(BASH_AVX2 ON BOOL)
  40. add_definitions(-DBASH_AVX2)
  41. elseif(BASH_PLATFORM STREQUAL "BASH_AVX512")
  42. set(BASH_AVX512 ON BOOL)
  43. add_definitions(-DBASH_AVX512)
  44. elseif(BASH_PLATFORM STREQUAL "BASH_NEON")
  45. set(BASH_NEON ON BOOL)
  46. add_definitions(-DBASH_NEON)
  47. elseif(NOT BASH_PLATFORM STREQUAL "BASH_64")
  48. message(WARNING "Unknown BASH_PLATFORM (${BASH_PLATFORM}). This option will be ignored")
  49. unset(BASH_PLATFORM CACHE)
  50. endif()
  51. endif()
  52. if (BASH_PLATFORM)
  53. message(STATUS "Requested BASH_PLATFORM: ${BASH_PLATFORM}")
  54. endif()
  55. # Lists of watnings:
  56. # * https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
  57. # * https://clang.llvm.org/docs/DiagnosticsReference.html
  58. set(CMAKE_C_WARNINGS
  59. "-Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings \
  60. -Wno-parentheses -Wno-unused-parameter -Wno-strict-aliasing \
  61. -Wno-xor-used-as-pow")
  62. if(CMAKE_COMPILER_IS_GNUCC)
  63. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARNINGS} -Wlogical-op")
  64. if(BASH_SSE2)
  65. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
  66. elseif(BASH_AVX2)
  67. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
  68. elseif(BASH_AVX512)
  69. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f -fno-asynchronous-unwind-tables")
  70. elseif(BASH_NEON)
  71. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  72. endif()
  73. set(CMAKE_C_FLAGS_RELEASE "-O2")
  74. set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
  75. set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 -coverage")
  76. set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-common -O3")
  77. set(CMAKE_C_FLAGS_ASANDBG "-fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  78. set(CMAKE_C_FLAGS_CHECK "-Werror -O1 -Wcast-qual -fanalyzer")
  79. endif(CMAKE_COMPILER_IS_GNUCC)
  80. if(CMAKE_COMPILER_IS_CLANG)
  81. set(CMAKE_C_WARNINGS "${CMAKE_C_WARNINGS} -Wno-parentheses-equality -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses")
  82. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARNINGS}")
  83. if(BASH_SSE2)
  84. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
  85. elseif(BASH_AVX2)
  86. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
  87. elseif(BASH_AVX512)
  88. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f -fno-asynchronous-unwind-tables")
  89. elseif(BASH_NEON)
  90. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  91. endif()
  92. set(CMAKE_C_FLAGS_RELEASE "-O2")
  93. set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
  94. set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 -coverage")
  95. set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O3")
  96. set(CMAKE_C_FLAGS_ASANDBG "-fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  97. set(CMAKE_C_FLAGS_MEMSAN "-fsanitize=memory -O3")
  98. set(CMAKE_C_FLAGS_MEMSANDBG "-fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
  99. set(CMAKE_C_FLAGS_CHECK "-Werror -O1 -Wcast-qual")
  100. endif(CMAKE_COMPILER_IS_CLANG)
  101. if(CMAKE_COMPILER_IS_MSVC)
  102. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  103. if(BASH_SSE2)
  104. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
  105. elseif(BASH_AVX2)
  106. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2")
  107. elseif(BASH_AVX512)
  108. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX512")
  109. endif()
  110. endif(CMAKE_COMPILER_IS_MSVC)
  111. if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
  112. if(CMAKE_COMPILER_IS_GNUCC)
  113. set(CMAKE_SHARED_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
  114. endif(CMAKE_COMPILER_IS_GNUCC)
  115. if(CMAKE_COMPILER_IS_CLANG)
  116. set(CMAKE_SHARED_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
  117. endif(CMAKE_COMPILER_IS_CLANG)
  118. endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
  119. if(BUILD_FAST)
  120. add_definitions(-DSAFE_FAST)
  121. endif()
  122. if(NOT LIB_INSTALL_DIR)
  123. set(LIB_INSTALL_DIR lib)
  124. endif()
  125. if(NOT BIN_INSTALL_DIR)
  126. set(BIN_INSTALL_DIR bin)
  127. endif()
  128. include_directories(include/)
  129. include_directories(src/)
  130. add_subdirectory(include)
  131. add_subdirectory(src)
  132. if(BUILD_CMD)
  133. add_subdirectory(cmd)
  134. endif()
  135. if(BUILD_TESTS)
  136. enable_testing()
  137. add_subdirectory(test)
  138. endif()
  139. if(BUILD_DOC)
  140. add_subdirectory(doc)
  141. endif()