-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
140 lines (121 loc) · 4.87 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
135
136
137
138
139
140
# **************************************************************************** #
# #
# ::: :::::::: #
# CMakeLists.txt :+: :+: :+: #
# +:+ +:+ +:+ #
# By: abelov <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/06/28 18:10:53 by abelov #+# #+# #
# Updated: 2024/06/28 18:10:53 by abelov ### ########.fr #
# #
# **************************************************************************** #
cmake_minimum_required(VERSION 3.8)
project(minishell C)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_STANDARD 99)
include_directories(include)
set(FT_CFLAGS
-Wall -Wextra -Werror
-Wwrite-strings -Wimplicit
-Wno-error=unused-parameter
-Wno-error=unused-function
-O0 -g3 -gdwarf-3
-masm=att -MMD
-fcf-protection=none -mmanual-endbr
-fno-exceptions
-ffunction-sections
-fdata-sections
-fno-dwarf2-cfi-asm
-fno-asynchronous-unwind-tables)
set(FT_CFLAGS
-Wall -Wextra -Werror
-Wwrite-strings
-Wimplicit
-Wno-error=unused-parameter
-O0
-masm=att
-fno-exceptions
-ffunction-sections
-fdata-sections
-fno-omit-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
)
set(COMMON_LDFLAGS
-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 "sub/*" )
file(GLOB_RECURSE TARGET_SOURCES "src/*.c")
list(FILTER TARGET_SOURCES EXCLUDE REGEX "src/sub/*")
set(TARGET_NAME "${PROJECT_NAME}_exe")
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(readline REQUIRED IMPORTED_TARGET readline)
set(TARGET_LIBRARIES
${FT_LIB_NAME}
Threads::Threads
PkgConfig::readline)
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_link_options(${TARGET_NAME} PRIVATE ${COMMON_LDFLAGS})
target_compile_options(${TARGET_NAME} PRIVATE
-fno-omit-frame-pointer
-fsanitize=address
-fsanitize=leak
"${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)