CMakeLists.txt 5.6 KB

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