-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
81 lines (68 loc) · 2.56 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
cmake_minimum_required(VERSION 3.0)
project(design_patterns LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 20)
option(build_cpp_lang "Build cpp_lang dir" OFF)
option(build_patterns "Build patterns dir" OFF)
option(build_parallel "Build cpp_lang dir" OFF)
option(build_not_single "Build cpp_lang dir" OFF)
option(build_json_test "Build json test dir" OFF)
option(build_unix_api "Build unix api dir" on)
option(build_eigen_test "Build eigen test" OFF)
option(define_debug "Define DEBUG macro" OFF)
if(define_debug)
add_definitions(-DDEBUG)
endif(define_debug)
enable_testing()
set(ROOT_DIR ${CMAKE_SOURCE_DIR})
include_directories(${ROOT_DIR}/include)
message(STATUS "C++ STANDARD: ${CMAKE_CXX_STANDARD}")
function(add_each dir_name)
file(GLOB cur_files ${dir_name}/*.cpp)
foreach(cur_file ${cur_files})
string(REPLACE ".cpp" "" cur_exe_file ${cur_file})
string(REPLACE "/" ";" cur_exe_file_list ${cur_exe_file})
list(LENGTH cur_exe_file_list list_len)
math(EXPR list_last "${list_len} - 1")
list(GET cur_exe_file_list ${list_last} cur_exe)
# message(STATUS "Added ${cur_exe}")
add_executable(${cur_exe} ${cur_file})
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${cur_exe} pthread atomic)
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_test(NAME ${cur_exe} COMMAND ${cur_exe})
endforeach()
endfunction()
function(add_each_notest dir_name)
file(GLOB cur_files ${dir_name}/*.cpp)
foreach(cur_file ${cur_files})
string(REPLACE ".cpp" "" cur_exe_file ${cur_file})
string(REPLACE "/" ";" cur_exe_file_list ${cur_exe_file})
list(LENGTH cur_exe_file_list list_len)
math(EXPR list_last "${list_len} - 1")
list(GET cur_exe_file_list ${list_last} cur_exe)
# message(STATUS "Added ${cur_exe}")
add_executable(${cur_exe} ${cur_file})
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${cur_exe} pthread atomic)
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
endforeach()
endfunction()
if(build_cpp_lang)
add_each(${ROOT_DIR}/cpp_lang)
endif(build_cpp_lang)
if(build_parallel)
add_each(${ROOT_DIR}/parallel)
endif(build_parallel)
if(build_patterns)
add_each(${ROOT_DIR}/patterns)
endif(build_patterns)
# add not_single_dir
set(not_single_dir ${CMAKE_SOURCE_DIR}/not_single)
if(build_not_single)
add_executable(inline_test ${not_single_dir}/inline01.cpp ${not_single_dir}/inline02.cpp)
add_executable(fstream_test ${not_single_dir}/fstream_test.cpp)
add_executable(extern_test ${not_single_dir}/extern_test_01.cpp ${not_single_dir}/extern_test_02.cpp)
endif(build_not_single)
if(build_unix_api)
add_each_notest(${ROOT_DIR}/unix_api)
endif(build_unix_api)