CMakeLists.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. cmake_minimum_required(VERSION 2.8)
  2. cmake_policy(SET CMP0003 NEW)
  3. project(SMHasher C CXX)
  4. include(CheckCCompilerFlag)
  5. # Check if the same compile family is used for both C and CXX
  6. if (NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID))
  7. message(WARNING "CMAKE_C_COMPILER_ID (${CMAKE_C_COMPILER_ID}) is different "
  8. "from CMAKE_CXX_COMPILER_ID (${CMAKE_CXX_COMPILER_ID})."
  9. "The final binary may be unusable.")
  10. endif()
  11. IF (CMAKE_MAJOR_VERSION GREATER 2)
  12. IF (CMAKE_MAJOR_VERSION GREATER 3 OR CMAKE_MINOR_VERSION GREATER 1)
  13. cmake_policy(SET CMP0056 OLD) # since 3.2. Honor link flags in try_compile() source-file signature.
  14. ENDIF()
  15. IF (CMAKE_MAJOR_VERSION GREATER 3 OR CMAKE_MINOR_VERSION GREATER 3)
  16. cmake_policy(SET CMP0065 NEW) # since 3.4. ENABLE_EXPORTS.
  17. ENDIF()
  18. IF (CMAKE_MAJOR_VERSION GREATER 3 OR CMAKE_MINOR_VERSION GREATER 6)
  19. cmake_policy(SET CMP0066 OLD) # since 3.7. Honor per-config flags in try_compile() source-file signature.
  20. ENDIF()
  21. include (TestBigEndian)
  22. TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
  23. if(IS_BIG_ENDIAN)
  24. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBIG_ENDIAN")
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBIG_ENDIAN")
  26. endif()
  27. endif()
  28. if(NOT CMAKE_BUILD_TYPE)
  29. set(CMAKE_BUILD_TYPE "Release" CACHE STRING
  30. "Choose the type of build, options are: Debug Release
  31. RelWithDebInfo MinSizeRel."
  32. FORCE)
  33. endif(NOT CMAKE_BUILD_TYPE)
  34. # TODO: rather parse `$CC -march=native -dM -E - <<< ''` [gh #10]
  35. IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
  36. EXEC_PROGRAM(cat ARGS "/proc/cpuinfo" OUTPUT_VARIABLE CPUINFO)
  37. STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE ${CPUINFO})
  38. STRING(COMPARE EQUAL "sse2" "${SSE_THERE}" SSE2_TRUE)
  39. STRING(REGEX REPLACE "^.*(sse4_2).*$" "\\1" SSE_THERE ${CPUINFO})
  40. STRING(COMPARE EQUAL "sse4_2" "${SSE_THERE}" SSE42_TRUE)
  41. set(FALKHASH_OBJ falkhash-elf64.o)
  42. STRING(REGEX REPLACE "^.*(aes).*$" "\\1" AES_THERE ${CPUINFO})
  43. STRING(COMPARE EQUAL "aes" "${AES_THERE}" AES_TRUE)
  44. ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin")
  45. EXEC_PROGRAM("/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE
  46. CPUINFO)
  47. STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO})
  48. STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE)
  49. STRING(REGEX REPLACE "^.*(SSE4.2).*$" "\\1" SSE_THERE ${CPUINFO})
  50. STRING(COMPARE EQUAL "SSE4.2" "${SSE_THERE}" SSE42_TRUE)
  51. set(FALKHASH_OBJ falkhash-macho64.o)
  52. STRING(REGEX REPLACE "^.*(AES).*$" "\\1" AES_THERE ${CPUINFO})
  53. STRING(COMPARE EQUAL "AES" "${AES_THERE}" AES_TRUE)
  54. ELSEIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  55. EXEC_PROGRAM("grep Features /var/run/dmesg.boot" OUTPUT_VARIABLE
  56. CPUINFO)
  57. STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO})
  58. STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE)
  59. STRING(REGEX REPLACE "^.*(SSE4.2).*$" "\\1" SSE_THERE ${CPUINFO})
  60. STRING(COMPARE EQUAL "SSE4.2" "${SSE_THERE}" SSE42_TRUE)
  61. set(FALKHASH_OBJ falkhash-elf64.o)
  62. STRING(REGEX REPLACE "^.*(AES).*$" "\\1" AES_THERE ${CPUINFO})
  63. STRING(COMPARE EQUAL "AES" "${AES_THERE}" AES_TRUE)
  64. ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
  65. if (CMAKE_COMPILER_IS_GNUCC
  66. OR (CMAKE_C_COMPILER_ID STREQUAL AppleClang)
  67. OR (CMAKE_C_COMPILER_ID STREQUAL Clang)
  68. OR (CMAKE_C_COMPILER_ID STREQUAL Intel))
  69. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  70. set(CMAKE_C_FLAGS_RELEASE "-O3")
  71. set(CMAKE_CXX_FLAGS_RELEASE "-O3")
  72. set(CMAKE_C_FLAGS_DEBUG "-g")
  73. set(CMAKE_CXX_FLAGS_DEBUG "-g")
  74. #IF (SSE2_TRUE)
  75. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
  76. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
  77. #ENDIF (SSE2_TRUE)
  78. #IF (SSE42_TRUE)
  79. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4")
  80. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4")
  81. #ENDIF (SSE42_TRUE)
  82. #IF (AES_TRUE)
  83. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
  84. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
  85. #ENDIF (AES_TRUE)
  86. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
  87. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
  88. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  89. # using Visual Studio C++
  90. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
  91. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
  92. else()
  93. message(WARNING "Unknown ${CMAKE_C_COMPILER_ID} compiler")
  94. # TODO: BSD and ARM8 crc detection
  95. # TODO: 32bit filter
  96. endif()
  97. IF (SSE2_TRUE)
  98. set(SSE2_FOUND true CACHE BOOL "SSE2 available")
  99. ELSE (SSE2_TRUE)
  100. set(SSE2_FOUND false CACHE BOOL "SSE2 not available")
  101. ENDIF (SSE2_TRUE)
  102. IF (SSE42_TRUE)
  103. set(SSE4_2_FOUND true CACHE BOOL "SSE4.2 available")
  104. ELSE (SSE42_TRUE)
  105. set(SSE4_2_FOUND false CACHE BOOL "SSE4.2 not available")
  106. ENDIF (SSE42_TRUE)
  107. IF (AES_TRUE)
  108. set(AES_FOUND true CACHE BOOL "AES-NI available")
  109. ELSE (AES_TRUE)
  110. set(AES_FOUND false CACHE BOOL "AES-NI not available")
  111. ENDIF (AES_TRUE)
  112. IF(AES_FOUND AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
  113. set(SSE4_OBJ ${FALKHASH_OBJ})
  114. ENDIF()
  115. IF(SSE4_2_FOUND)
  116. SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
  117. set(SSE2_SRC hasshe2.c)
  118. set(SSE4_SRC crc32_hw.c)
  119. # 64bit only:
  120. IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
  121. #enable_language(ASM-NASM)
  122. #set(CMAKE_ASM_FLAGS "-f elf64")
  123. set(SSE4_SRC1 crc32_hw1.c)
  124. set(METROCRC64_SRC metrohash64crc.cpp)
  125. set(METROCRC128_SRC metrohash128crc.cpp)
  126. ENDIF()
  127. set(SIPHASH_SRC siphash_ssse3.c)
  128. ELSEIF(SSE2_FOUND)
  129. set(SSE2_SRC hasshe2.c)
  130. set(SIPHASH_SRC siphash_sse2.c)
  131. ELSE()
  132. set(SIPHASH_SRC siphash.c)
  133. ENDIF(SSE4_2_FOUND)
  134. IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
  135. set(64ONLY_SRC
  136. xxhash.c metrohash64.cpp metrohash128.cpp farmhash.cc
  137. FarmTest.cc farmhash-c.c farmhash-c-test.cc cmetrohash64.c
  138. opt_cmetrohash64_1.c fasthash.cpp)
  139. ENDIF()
  140. add_library(
  141. SMHasherSupport
  142. AvalancheTest.cpp
  143. Bitslice.cpp
  144. Bitvec.cpp
  145. CityTest.cpp
  146. City.cpp
  147. crc.cpp
  148. DifferentialTest.cpp
  149. Hashes.cpp
  150. ${SSE2_SRC}
  151. ${SSE4_SRC}
  152. ${SSE4_SRC1}
  153. KeysetTest.cpp
  154. lookup3.cpp
  155. md5.cpp
  156. MurmurHash1.cpp
  157. MurmurHash2.cpp
  158. MurmurHash3.cpp
  159. Platform.cpp
  160. Random.cpp
  161. sha1.cpp
  162. ${SIPHASH_SRC}
  163. SpeedTest.cpp
  164. Spooky.cpp
  165. SpookyTest.cpp
  166. Stats.cpp
  167. SuperFastHash.cpp
  168. Types.cpp
  169. PMurHash.c
  170. ${64ONLY_SRC}
  171. ${METROCRC64_SRC}
  172. ${METROCRC128_SRC}
  173. ${SSE4_OBJ}
  174. t1ha.c
  175. mum.cc
  176. )
  177. add_executable(
  178. SMHasher
  179. main.cpp
  180. )
  181. target_link_libraries(
  182. SMHasher
  183. SMHasherSupport
  184. ${CMAKE_THREAD_LIBS_INIT}
  185. )