Skip to content

Commit 3585aa2

Browse files
committed
add cmake
1 parent 4775659 commit 3585aa2

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.exe
2+
.idea

CMakeLists.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(ParallelRadixSort)
3+
4+
# 设置 C++ 标准
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
8+
9+
# 添加 pthread 支持(Linux/macOS)
10+
if(UNIX AND NOT APPLE)
11+
find_package(Threads REQUIRED)
12+
endif()
13+
14+
# 可选宏定义:通过 cmake -DDEBUG=ON 控制
15+
option(DEBUG "Enable debug mode" OFF)
16+
if(DEBUG)
17+
add_compile_definitions(DEBUG)
18+
endif()
19+
20+
# 可选宏定义:RADIX_SORT_MIN_SIZE,用法:cmake -DRADIX_SORT_MIN_SIZE=100 ..
21+
set(RADIX_SORT_MIN_SIZE "" CACHE STRING "Minimum size for radix sort")
22+
if(RADIX_SORT_MIN_SIZE)
23+
add_compile_definitions(RADIX_SORT_MIN_SIZE=${RADIX_SORT_MIN_SIZE})
24+
endif()
25+
26+
# 可选宏定义:TEST_OPTION_PARSER,用法:cmake -DTEST_OPTION_PARSER=ON ..
27+
option(TEST_OPTION_PARSER "Enable test option parser" OFF)
28+
if(TEST_OPTION_PARSER)
29+
add_compile_definitions(TEST_OPTION_PARSER)
30+
endif()
31+
32+
# 源文件和头文件
33+
set(SOURCES test.cpp)
34+
set(HEADERS Options.h ParallelRadixSort.h ThreadPool.h)
35+
36+
# 目标可执行文件名
37+
if(WIN32)
38+
set(TEST_EXECUTABLE test.exe)
39+
else()
40+
set(TEST_EXECUTABLE test)
41+
endif()
42+
43+
add_executable(${TEST_EXECUTABLE} ${SOURCES} ${HEADERS})
44+
45+
# 链接 pthread(Linux/macOS)
46+
if(UNIX AND NOT APPLE)
47+
target_link_libraries(${TEST_EXECUTABLE} PRIVATE Threads::Threads)
48+
endif()
49+
50+
# 定义 clean 和 help(虽然 CMake 不推荐自定义 clean,但可以模拟)
51+
add_custom_target(cleantarget
52+
COMMAND ${CMAKE_COMMAND} -E remove ${TEST_EXECUTABLE}
53+
COMMENT "Cleaning build files"
54+
)
55+
56+
add_custom_target(helptarget
57+
COMMAND ${CMAKE_COMMAND} -E echo "Build the project with optional defines:"
58+
COMMAND ${CMAKE_COMMAND} -E echo " -DDEBUG=ON"
59+
COMMAND ${CMAKE_COMMAND} -E echo " -DRADIX_SORT_MIN_SIZE=INT"
60+
COMMAND ${CMAKE_COMMAND} -E echo " -DTEST_OPTION_PARSER=ON"
61+
)

test

-213 KB
Binary file not shown.

0 commit comments

Comments
 (0)