-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
90 lines (71 loc) · 2.79 KB
/
CMakeLists.txt
File metadata and controls
90 lines (71 loc) · 2.79 KB
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
cmake_minimum_required(VERSION 3.20)
project(CS50x C)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Set a default build type if none is specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Helpful for debugging (CLion usually does this in Debug, but explicit is fine)
# -fsanitize=address -fsanitize=leak
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g -fno-omit-frame-pointer -fsanitize=address -fsanitize=leak \
-Wall -Werror -Wno-unknown-attributes")
# Use add_compile_options with generator expressions to robustly add release flags
# This ensures they are applied even if the cache has old values.
add_compile_options($<$<CONFIG:Release>:-O3>)
add_compile_options($<$<CONFIG:Release>:-march=native>)
add_compile_options($<$<CONFIG:Release>:-DNDEBUG>)
# 1. Explicitly define your library/shared code
add_executable(string_buffer roblib/string_buffer.c roblib/string_buffer.h)
# Explicit target matching your manual clang command:
add_executable(test_hashmap2
roblib/map/test_hashmap2.c
roblib/map/hashmap.c
roblib/collections.c
roblib/map/string_counter.c
roblib/memory/memory_pool.c
roblib/munit/munit.c
)
target_compile_definitions(test_hashmap2 PRIVATE TEST_HASHMAP)
target_compile_options(test_hashmap2 PRIVATE -Wno-unused-function)
add_executable(string_counter
roblib/map/test_string_counter.c
roblib/map/string_counter.c
roblib/collections.c
roblib/munit/munit.c
roblib/memory/memory_pool.c
roblib/map/test_hashmap.c
roblib/map/hashmap.c
)
target_compile_definitions(string_counter PRIVATE TEST_STRING_COUNTER)
add_executable(test_array_list
roblib/list/test_array_list.c
roblib/collections.c
roblib/list/array_list.c
roblib/memory/memory_pool.c
roblib/munit/munit.c
)
target_compile_definitions(test_array_list PRIVATE TEST_ARRAY_LIST)
add_executable(all_tests
roblib/all_tests.c
roblib/collections.c
roblib/munit/munit.c
roblib/memory/memory_pool.c
roblib/map/test_hashmap.c
roblib/map/hashmap.c
roblib/map/string_counter.c
roblib/map/test_string_counter.c
roblib/list/test_array_list.c
roblib/list/array_list.c
)
add_executable( hashing CS50X/week5/hashing.c CS50X/week5/hash_methods.c )
# 2. AUTOMATION: Find all other .c files and make them executables
# This is great for "learning" repos where every file has a main()
file(GLOB_RECURSE ALL_SOURCES "*.c")
foreach(SOURCE_FILE ${ALL_SOURCES})
get_filename_component(TARGET_NAME ${SOURCE_FILE} NAME_WE)
# Check if target already exists to avoid duplicates (like string_buffer above)
if(NOT TARGET ${TARGET_NAME})
add_executable(${TARGET_NAME} ${SOURCE_FILE})
endif()
endforeach()