-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
52 lines (38 loc) · 1.89 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
cmake_minimum_required(VERSION 3.20)
project(ThreadPool)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 设置 C 编译器的优化等级
set(CMAKE_C_FLAGS_RELEASE "-O2") # 为 Release 类型设置 -O2 优化
set(CMAKE_C_FLAGS_DEBUG "-g") # 为 Debug 类型设置 -g(生成调试信息),不设置优化
# 设置 C++ 编译器的优化等级
set(CMAKE_CXX_FLAGS_RELEASE "-O2") # 为 Release 类型设置 -O2 优化
set(CMAKE_CXX_FLAGS_DEBUG "-g") # 为 Debug 类型设置 -g(生成调试信息),不设置优化
# Set the include directories
include_directories(include)
# Add the source files
set(SOURCES src/thread_pool.cpp src/worker_thread.cpp)
# Generate the shared library
# 如果是 MSVC 编译器,则生成静态库 # If the compiler is MSVC, generate a static library
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message("Use MSVC!")
add_library(ThreadPool STATIC ${SOURCES})
else()
add_library(ThreadPool SHARED ${SOURCES})
endif()
# Set the output directory for the library
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set_target_properties(ThreadPool PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
add_executable(FunctionalTest tests/functional_test.cpp)
add_executable(PerformanceTest tests/performance_test.cpp)
target_link_libraries(FunctionalTest PRIVATE ThreadPool)
target_link_libraries(PerformanceTest PRIVATE ThreadPool)
# Set the output directory for the test executable
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set_target_properties(FunctionalTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set_target_properties(PerformanceTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
# Add the test executable
add_test(NAME FunctionalTest COMMAND FunctionalTest)
add_test(NAME PerformanceTest COMMAND PerformanceTest)
# Add the test executable to the list of tests
enable_testing()