-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
65 lines (50 loc) · 1.75 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
cmake_minimum_required(VERSION 3.12)
# Set the project name and version
project(cy_daily VERSION 1.0)
# Define build options
option(BUILD_HASH "Build hash cpp" OFF)
option(BUILD_DOUBLE_POINTER "Build double pointer cpp" OFF)
option(BUILD_DP "Build dp cpp" ON)
option(BUILD_DEBUG "Enable gcc -g option" ON)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Compiler option
add_compile_options(-Wall -Wextra -Wpedantic)
# Create a separate build directory
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Make sure the build directory exists
file(MAKE_DIRECTORY ${BUILD_DIR})
# Move to the build directory
execute_process(
COMMAND ${CMAKE_COMMAND} -E chdir ${BUILD_DIR}
)
# Macro to build all source file
macro(add_executables_from_subdirectory subdir)
file(MAKE_DIRECTORY ${BUILD_DIR}/${subdir})
file(GLOB SOURCES "${subdir}/*.cpp")
foreach(SOURCE ${SOURCES})
get_filename_component(EXEC_NAME ${SOURCE} NAME_WE)
add_executable(${EXEC_NAME} ${SOURCE})
target_include_directories(${EXEC_NAME} PRIVATE ${INC_DIR})
set_target_properties(${EXEC_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR}/${subdir})
endforeach()
endmacro()
# Build with debug
if(BUILD_DEBUG)
set(CMAKE_BUILD_TYPE Debug)
endif()
# Optionally, build tests based on the BUILD_TESTS option
if(BUILD_HASH)
add_executables_from_subdirectory(hash)
message(STATUS "Build hash test")
endif()
if(BUILD_DOUBLE_POINTER)
add_executables_from_subdirectory(double_pointer)
message(STATUS "Build double pointer test")
endif()
if(BUILD_DP)
add_executables_from_subdirectory(dynamic_programming)
message(STATUS "Build dp test")
endif()