forked from GioStil/CS527_skiplist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
134 lines (106 loc) · 3.95 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
include(PreventInSouceBuilds.cmake.in)
cmake_minimum_required(VERSION 3.17)
project(
minos
VERSION 1.0.0
LANGUAGES C CXX)
option(USE_SANITIZER "Use sanitizer: Address, Thread, Memory, Undefined" "")
if(NOT (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}))
set(BUILD_TESTING False)
else()
set(BUILD_TESTING True)
endif()
# Add sanitizer options if enabled
if(USE_SANITIZER)
if(USE_SANITIZER STREQUAL "Address")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_CLANG_TIDY "")
option(BUILD_SHARED_LIBS
"Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON)
# Set a default build type if none was specified
set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "Debug")
endif()
# Set default build type to Release if none is specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(default_build_type "Release")
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Print the build type being used
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
# Add definition for release build
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DRELEASE_BUILD)
endif()
include(FetchContent)
include(CTest)
include(GNUInstallDirs)
set(SOURCE_FILES src/minos.c)
find_package(Threads REQUIRED)
FetchContent_Declare(
cmake-scripts
GIT_REPOSITORY https://github.com/StableCoder/cmake-scripts.git
GIT_TAG main
GIT_PROGRESS TRUE)
FetchContent_GetProperties(cmake-scripts)
if(NOT cmake-scripts_POPULATED)
FetchContent_Populate(cmake-scripts)
FetchContent_MakeAvailable(cmake-scripts)
include(${cmake-scripts_SOURCE_DIR}/sanitizers.cmake)
endif()
add_subdirectory(tests)
add_library(${PROJECT_NAME} ${SOURCE_FILES})
target_include_directories(
${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME minos
CLEAN_DIRECT_OUTPUT 1)
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads log)
find_program(iwyu_path NAMES include-what-you-use iwyu iwyu-tool)
if(iwyu_path)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_INCLUDE_WHAT_YOU_USE
${iwyu_path})
else()
message("Could not find the program include-what-you-use")
endif()
install(
TARGETS ${PROJECT_NAME}
EXPORT minos
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY include/ DESTINATION include)
install(EXPORT minos DESTINATION share/${PROJECT_NAME}/cmake)
set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
log
GIT_REPOSITORY https://github.com/innerout/log.c.git
GIT_PROGRESS TRUE)
FetchContent_GetProperties(log)
if(NOT log_POPULATED)
FetchContent_Populate(log)
add_subdirectory(${log_SOURCE_DIR} ${log_BINARY_DIR})
FetchContent_MakeAvailable(log)
endif()
export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}.cmake)
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()