Skip to content

Commit b245648

Browse files
committed
add snippet and cross platform
1 parent cae0c67 commit b245648

10 files changed

Lines changed: 128 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
_test.cpp
33
a.out
44
.buildme
5+
build/

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required (VERSION 3.12)
2+
3+
set (CMAKE_CXX_STANDARD 11)
4+
5+
project ("Thread Sorter")
6+
7+
# configuring compiler cross platform
8+
if (CMAKE_HOST_WIN32)
9+
include (config-win32.cmake)
10+
11+
elseif (CMAKE_HOST_UNIX)
12+
include (config-unix.cmake)
13+
14+
else ()
15+
message (FATAL_ERROR "Unknown platform.")
16+
17+
endif ()
18+
19+
aux_source_directory ("${PROJECT_SOURCE_DIR}/src" PROJECT_SOURCE_FILES)
20+
add_library (lzxthreadsorter SHARED ${PROJECT_SOURCE_FILES})
21+
22+
add_subdirectory ("snippet")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# thread-pool-sort
1+
# thread-sorter
22

33
一个线程池应用,可实现对海量数据排序。
44

config-unix.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
message ("-- Building on Linux ...")
2+
3+
# configure compiler gcc with Ccache
4+
set (CMAKE_C_COMPILER "gcc")
5+
set (CMAKE_CXX_COMPILER "g++")
6+
7+
message ("-- Using C Compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_VERSION})")
8+
message ("-- Using C++ Compiler: ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_VERSION})")

config-win32.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
message ("-- Building on Win32 ...")
2+
3+
message ("-- Using C Compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_VERSION})")
4+
message ("-- Using C++ Compiler: ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_VERSION})")
5+
6+
# using warning options W2
7+
option (SUPRESS_W3_WARNINGS "Configure warning level to /W2" ON)
8+
if (SUPRESS_W3_WARNINGS)
9+
add_compile_options ("/W2")
10+
endif ()
11+
12+
# configure compiler MSVC with Ccache
13+
# please use MSVC to satisfy Ccache, not other compilers
14+
add_compile_options ("/Z7")
15+
16+
find_program (CCACHE_EXECUTABLE ccache)
17+
if (CCACHE_EXECUTABLE)
18+
message ("-- Ccache executable found at: ${CCACHE_EXECUTABLE}")
19+
file (COPY "${CCACHE_EXECUTABLE}" DESTINATION "${PROJECT_BINARY_DIR}")
20+
file (RENAME "${PROJECT_BINARY_DIR}/ccache.exe" "${PROJECT_BINARY_DIR}/cl.exe")
21+
set (CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
22+
set (CMAKE_VS_GLOBALS
23+
"CLToolExe=cl.exe"
24+
"CLToolPath=${PROJECT_BINARY_DIR}"
25+
"TrackFileAccess=false"
26+
"UseMultiToolTask=true"
27+
"DebugInformationFormat=OldStyle"
28+
)
29+
30+
else ()
31+
message ("-- CCache not found.")
32+
33+
endif ()

snippet/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Collect snippets marked as being built
2+
3+
file (GLOB ITEMS RELATIVE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/*)
4+
set (SUB_DIRS "")
5+
foreach (ITEM ${ITEMS})
6+
if (
7+
IS_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/${ITEM}
8+
AND EXISTS ${CMAKE_CURRENT_LIST_DIR}/${ITEM}/CMakeLists.txt
9+
AND EXISTS ${CMAKE_CURRENT_LIST_DIR}/${ITEM}/.buildme
10+
)
11+
list (APPEND SUB_DIRS ${ITEM})
12+
13+
endif()
14+
15+
endforeach()
16+
17+
# Run add_subdirectory() for each
18+
19+
foreach (SUB_DIR ${SUB_DIRS})
20+
message ("-- [LarkSDK] Building snippet: ${SUB_DIR}")
21+
add_subdirectory (${SUB_DIR})
22+
23+
endforeach()
24+
25+
message ("-- Done configuring snippets")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_executable (TemporaryTest main.cpp)
2+
target_link_libraries (TemporaryTest lzxthreadsorter)

snippet/TemporaryTest/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <iostream>
2+
3+
4+
int main()
5+
{
6+
std::cout << __cplusplus << std::endl;
7+
8+
9+
return 0;
10+
}

src/lthreadpool.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @file lthreadpool.cpp
3+
* @author DavidingPlus (davidingplus@qq.com)
4+
* @brief 线程池类源文件。
5+
* @date 2024-10-21
6+
*
7+
* Copyright (c) 2024 电子科技大学 刘治学
8+
*
9+
*/
10+
11+
#include "lthreadpool.h"

src/lthreadpool.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @file lthreadpool.h
3+
* @author DavidingPlus (davidingplus@qq.com)
4+
* @brief 线程池类头文件。
5+
* @date 2024-10-21
6+
*
7+
* Copyright (c) 2024 电子科技大学 刘治学
8+
*
9+
*/
10+
11+
#ifndef _LTHREADPOOL_H_
12+
#define _LTHREADPOOL_H_
13+
14+
15+
#endif

0 commit comments

Comments
 (0)