-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
100 lines (77 loc) · 3.41 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# COPYRIGHT (c) 2019-2021 Habanalabs Ltd. See COPYING.md file
cmake_minimum_required(VERSION 3.0.1 FATAL_ERROR)
# Specify search path for CMake modules to be loaded by include()
# and find_package()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
# Add defaults for cmake
# Those need to be set before the project() call.
include(DefineCMakeDefaults)
include(DefineCompilerFlags)
project(hl-thunk LANGUAGES C)
# Reduce "warm" compilation time if ccache is available
find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
set(HLTHUNK "hl-thunk")
set(HLTHUNK_PACKAGE "hl-thunk")
set(HLTHUNK_COMPONENT "lib${HLTHUNK}")
set(HLTHUNK_TARGET "${HLTHUNK}")
set(HLTHUNK_ERR_INJECT "hl-thunk-err_injection")
set(HLTHUNK_ERR_INJECT_PACKAGE "hl-thunk-err_injection")
set(HLTHUNK_ERR_INJECT_COMPONENT "lib${HLTHUNK_ERR_INJECT}")
set(HLTHUNK_ERR_INJECT_TARGET "${HLTHUNK_ERR_INJECT}")
include(GNUInstallDirs)
set(BUILD_VERSION_MAJOR ${VERSION_MAJOR})
set(BUILD_VERSION_MINOR ${VERSION_MINOR})
set(BUILD_VERSION_PATCH ${VERSION_PATCH})
set(LIB_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}")
if (NOT ALLOW_IN_SOURCE_BUILD)
include(MacroEnsureOutOfSourceBuild)
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
endif()
# Copy library files to a lib sub-directory
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "-fPIC -W -Werror -Wall -Wextra -Wno-unused-parameter")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers -Wno-type-limits")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function -Wno-sign-compare")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-security -Wswitch-default -Wundef")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wpointer-arith -Wcast-qual")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes -Wredundant-decls")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunreachable-code -fvisibility=hidden")
# -Wl,--no-as-needed -ldl flag is needed for dynamic library loading (for profiler use)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--no-as-needed -ldl")
if (CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable -Wlogical-op")
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-truncation -Wno-format-truncation")
endif()
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL Release)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0")
endif()
if (SANITIZE_ON)
set(SANITIZE "-fsanitize=undefined")
set(SANITIZE "${SANITIZE} -fsanitize=leak")
set(SANITIZE "${SANITIZE} -fno-omit-frame-pointer -fsanitize=address")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE}")
include_directories(include)
add_subdirectory(src)
add_subdirectory(err_inject)
if (HLTESTS_LIB_MODE)
add_definitions(-DHLTESTS_LIB_MODE)
add_subdirectory(tests)
else ()
if (UNIT_TESTING)
find_package(CMocka 1.1.3 REQUIRED)
include(AddCMockaTest)
add_subdirectory(tests)
endif ()
endif ()