-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
116 lines (99 loc) · 4.26 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
# **************************************************************************** #
# #
# ::: :::::::: #
# CMakeLists.txt :+: :+: :+: #
# +:+ +:+ +:+ #
# By: abelov <abelov@student.42london.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/13 18:05:20 by abelov #+# #+# #
# Updated: 2024/09/13 18:05:21 by abelov ### ########.fr #
# #
# **************************************************************************** #
cmake_minimum_required(VERSION 3.8)
project(philosophers C)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_STANDARD 99)
include_directories(include)
set(FT_LDFLAGS
-fsanitize=address
-fsanitize=undefined
-fno-sanitize-recover
-fsanitize=float-divide-by-zero
-fsanitize=float-cast-overflow)
set(FT_CFLAGSFT_CFLAGS
-Wall -Wextra -Werror
-Wwrite-strings -Wimplicit
-Wno-error=unused-parameter
-Wno-error=unused-function
-O0
-masm=att
-ffunction-sections
-fdata-sections
-fomit-frame-pointer
-fdwarf2-cfi-asm
-fcf-protection=none
-mmanual-endbr
-g3 -gdwarf-3
-fasynchronous-unwind-tables
-fsanitize=address
-fsanitize=undefined
-fno-sanitize-recover
-fsanitize=float-divide-by-zero
-fsanitize=float-cast-overflow)
#==============================================================================#
# FT lib
#==============================================================================#
set(FT_LIB_NAME ft)
set(FT_LIB_FILENAME libft.a)
set(FT_LIB_DIR "${PROJECT_SOURCE_DIR}/lib/ft")
file(GLOB_RECURSE FT_LIB_HEADERS "${FT_LIB_DIR}/*.h")
file(GLOB_RECURSE FT_LIB_SOURCES "${FT_LIB_DIR}/ft_*.c")
add_custom_target(${FT_LIB_NAME}_target ALL
COMMAND make -C ${FT_LIB_DIR}
BYPRODUCTS "${FT_LIB_DIR}/${FT_LIB_FILENAME}"
SOURCES "${FT_LIB_HEADERS};${FT_LIB_SOURCES}"
COMMENT "Building FT_LIB")
add_library(${FT_LIB_NAME} STATIC IMPORTED)
add_dependencies(${FT_LIB_NAME} "${FT_LIB_NAME}_target")
set_target_properties(${FT_LIB_NAME} PROPERTIES
IMPORTED_LOCATION ${FT_LIB_DIR}/${FT_LIB_FILENAME}
INTERFACE_COMPILE_DEFINITIONS ""
INTERFACE_LINK_OPTIONS ""
INTERFACE_SOURCES "${FT_LIB_HEADERS}"
INTERFACE_INCLUDE_DIRECTORIES "${FT_LIB_DIR};${FT_LIB_DIR}/include;${FT_LIB_DIR}/include/ft")
#==============================================================================#
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/scratch")
if(EXISTS "${PROJECT_SOURCE_DIR}/scratch/CMakeLists.txt")
add_subdirectory(scratch)
endif()
endif()
file(GLOB_RECURSE TARGET_HEADERS "src/*.h")
list(FILTER TARGET_HEADERS EXCLUDE REGEX "bonus/*" )
file(GLOB_RECURSE TARGET_SOURCES "src/*.c")
list(FILTER TARGET_SOURCES EXCLUDE REGEX "bonus/*")
set(TARGET_NAME "${PROJECT_NAME}_exe")
find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(TARGET_LIBRARIES
${FT_LIB_NAME}
Threads::Threads)
add_executable(${TARGET_NAME}
${TARGET_HEADERS}
${TARGET_SOURCES})
target_include_directories(${TARGET_NAME} PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(${TARGET_NAME} "${TARGET_LIBRARIES}")
target_compile_options(${TARGET_NAME} PRIVATE "${FT_CFLAGS}")
set_target_properties(${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_NAME "${PROJECT_NAME}")
#==============================================================================#
# Custom targets
#==============================================================================#
add_custom_target(fclean
COMMAND make -C ${FT_LIB_DIR} fclean)
add_custom_target(re
COMMAND make -C ${FT_LIB_DIR} re
COMMAND make -C ${PROJECT_SOURCE_DIR} re)
add_custom_target(norm
COMMAND make -C ${FT_LIB_DIR} norm
COMMAND make -C ${PROJECT_SOURCE_DIR} norm)