-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
84 lines (68 loc) · 2.21 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
cmake_minimum_required (VERSION 3.2)
project (cpu_check VERSION 20181130 LANGUAGES C CXX)
# Options
# Use clang/llvm by default.
option(USE_CLANG "build with clang" ON)
# Build semi-statically by default.
option(BUILD_STATIC "build targets semi-statically linked" ON)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
# Config header
configure_file (
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
include_directories("${PROJECT_BINARY_DIR}")
if (USE_CLANG)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CC clang)
set(CXX clang++)
endif(USE_CLANG)
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -O0")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -O0")
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2")
set(CMAKE_CXX_FLAGS_RELEASE "-Wall -O2")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF) # we want c11 not gnu11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # we want c++11 not gnu++11
add_executable(cpu_check cpu_check.cc)
add_executable(crc32c_test crc32c_test.cc)
add_library(farmhash farmhash.cc)
add_library(crc32c crc32c.c)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-march=sandybridge" ARCH_SANDYBRIDGE)
if(ARCH_SANDYBRIDGE)
target_compile_options(farmhash PUBLIC -march=sandybridge)
target_compile_options(crc32c PUBLIC -march=sandybridge)
endif(ARCH_SANDYBRIDGE)
target_link_libraries(cpu_check crc32c farmhash)
target_link_libraries(crc32c_test crc32c)
if (BUILD_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif(BUILD_STATIC)
# Needs pthreads
find_package(Threads REQUIRED)
target_link_libraries(cpu_check Threads::Threads)
# Needs zlib
find_package (ZLIB REQUIRED)
if(ZLIB_INCLUDE_DIRS)
include_directories(${ZLIB_INCLUDE_DIRS})
endif(ZLIB_INCLUDE_DIRS)
if(ZLIB_LIBRARIES)
target_link_libraries(cpu_check ${ZLIB_LIBRARIES})
endif(ZLIB_LIBRARIES)
# Needs OpenSSL
find_package (OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIRS})
target_link_libraries(cpu_check ${OPENSSL_LIBRARIES})
# Static linking of OpenSSL may require -ldl, link it if found.
find_library (dl dl)
if(dl)
target_link_libraries(cpu_check dl)
endif(dl)
install (TARGETS cpu_check DESTINATION bin)