Skip to content

Commit 754661c

Browse files
authored
Merge pull request #59 from mutouyun/master
2 parents d74f4c5 + 78be14b commit 754661c

31 files changed

+484
-679
lines changed

.github/workflows/c-cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: C/C++ CI
22

33
on:
44
push:
5-
branches: [ master, develop ]
5+
branches: [ master, develop, issue-* ]
66
pull_request:
77
branches: [ master, develop ]
88

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ CMakeLists.txt.user*
4444

4545
# My output files
4646
build
47+
48+
# vs
49+
.vs
4750
.vscode

3rdparty/gtest/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
# ctest. You can select which tests to run using 'ctest -R regex'.
99
# For more options, run 'ctest --help'.
1010

11+
if (POLICY CMP0077)
12+
cmake_policy(SET CMP0077 NEW)
13+
endif (POLICY CMP0077)
14+
1115
# When other libraries are using a shared version of runtime libraries,
1216
# Google Test also has to use one.
1317
option(
1418
gtest_force_shared_crt
1519
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
16-
ON)
20+
OFF)
1721

1822
option(gtest_build_tests "Build all of gtest's own tests." OFF)
1923

CMakeLists.txt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,48 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(cpp-ipc)
33

4-
option(LIBIPC_BUILD_TESTS "Build all of libipc's own tests." OFF)
5-
option(LIBIPC_BUILD_DEMOS "Build all of libipc's own demos." OFF)
4+
option(LIBIPC_BUILD_TESTS "Build all of libipc's own tests." OFF)
5+
option(LIBIPC_BUILD_DEMOS "Build all of libipc's own demos." OFF)
6+
option(LIBIPC_BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
7+
option(LIBIPC_USE_STATIC_CRT "Set to ON to build with static CRT on Windows (/MT)." OFF)
68

9+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
710
set(CMAKE_CXX_STANDARD 17)
811
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
912
if(NOT MSVC)
1013
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
1114
endif()
1215

13-
include_directories(${CMAKE_SOURCE_DIR}/include)
16+
if (MSVC AND LIBIPC_USE_STATIC_CRT)
17+
set(CompilerFlags
18+
CMAKE_CXX_FLAGS
19+
CMAKE_CXX_FLAGS_DEBUG
20+
CMAKE_CXX_FLAGS_RELEASE
21+
CMAKE_C_FLAGS
22+
CMAKE_C_FLAGS_DEBUG
23+
CMAKE_C_FLAGS_RELEASE
24+
)
25+
foreach(CompilerFlag ${CompilerFlags})
26+
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
27+
endforeach()
28+
endif()
1429

1530
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
1631
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
1732
set(LIBIPC_PROJECT_DIR ${PROJECT_SOURCE_DIR})
1833

34+
# Unicode Support
35+
add_definitions(-DUNICODE -D_UNICODE)
36+
1937
add_subdirectory(src)
2038

2139
if (LIBIPC_BUILD_TESTS)
2240
set(GOOGLETEST_VERSION 1.10.0)
41+
if (LIBIPC_USE_STATIC_CRT)
42+
set(gtest_force_shared_crt OFF)
43+
else()
44+
set(gtest_force_shared_crt ON)
45+
endif()
2346
add_subdirectory(3rdparty/gtest)
2447
add_subdirectory(test)
2548
endif()
@@ -30,6 +53,6 @@ if (LIBIPC_BUILD_DEMOS)
3053
endif()
3154

3255
install(
33-
DIRECTORY "include/"
34-
DESTINATION "include"
56+
DIRECTORY "include/"
57+
DESTINATION "include"
3558
)

demo/msg_que/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ constexpr std::size_t const max_sz = 1024 * 16;
2323
std::atomic<bool> is_quit__{ false };
2424
std::atomic<std::size_t> size_counter__{ 0 };
2525

26-
using msg_que_t = ipc::chan<ipc::relat::single, ipc::relat::single, ipc::trans::unicast>;
26+
using msg_que_t = ipc::chan<ipc::relat::single, ipc::relat::multi, ipc::trans::broadcast>;
2727

2828
msg_que_t que__{ name__ };
2929
ipc::byte_t buff__[max_sz];

include/libipc/def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum : std::uint32_t {
3333
enum : std::size_t {
3434
data_length = 64,
3535
large_msg_limit = data_length,
36-
large_msg_align = 512,
36+
large_msg_align = 1024,
3737
large_msg_cache = 32,
3838
};
3939

include/libipc/export.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
*/
4545

4646
#ifndef IPC_EXPORT
47-
#if defined(__IPC_LIBRARY__)
47+
#if defined(LIBIPC_LIBRARY_SHARED_BUILDING__)
4848
# define IPC_EXPORT IPC_DECL_EXPORT
49-
#else
49+
#elif defined(LIBIPC_LIBRARY_SHARED_USING__)
5050
# define IPC_EXPORT IPC_DECL_IMPORT
51+
#else
52+
# define IPC_EXPORT
5153
#endif
5254
#endif /*IPC_EXPORT*/

include/libipc/pool_alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ inline void free(void* p, std::size_t size) {
9494

9595
template <typename T>
9696
void free(T* p) {
97+
if (p == nullptr) return;
9798
destruct(p);
9899
pool_alloc::free(p, sizeof(T));
99100
}

include/libipc/tls_pointer.h

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/CMakeLists.txt

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
project(ipc)
22

3-
add_compile_options(-D__IPC_LIBRARY__)
4-
5-
if(NOT MSVC)
6-
add_compile_options(-fPIC)
7-
endif()
8-
9-
include_directories(
10-
${LIBIPC_PROJECT_DIR}/include
11-
${LIBIPC_PROJECT_DIR}/src)
12-
133
if(UNIX)
144
file(GLOB SRC_FILES ${LIBIPC_PROJECT_DIR}/src/libipc/platform/*_linux.cpp)
155
else()
@@ -26,14 +16,44 @@ file(GLOB HEAD_FILES
2616
${LIBIPC_PROJECT_DIR}/src/libipc/platform/*.h
2717
${LIBIPC_PROJECT_DIR}/src/libipc/utility/*.h)
2818

29-
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES})
19+
if (LIBIPC_BUILD_SHARED_LIBS)
20+
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES})
21+
target_compile_definitions(${PROJECT_NAME}
22+
INTERFACE
23+
LIBIPC_LIBRARY_SHARED_USING__
24+
PRIVATE
25+
LIBIPC_LIBRARY_SHARED_BUILDING__)
26+
else()
27+
add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES})
28+
endif()
29+
30+
# set output directory
31+
set_target_properties(${PROJECT_NAME}
32+
PROPERTIES
33+
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
34+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
35+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" )
36+
37+
# set version
38+
set_target_properties(${PROJECT_NAME}
39+
PROPERTIES
40+
VERSION 1.0.0
41+
SOVERSION 1)
42+
43+
target_include_directories(${PROJECT_NAME}
44+
PUBLIC ${LIBIPC_PROJECT_DIR}/include
45+
PRIVATE ${LIBIPC_PROJECT_DIR}/src
46+
)
47+
3048
if(NOT MSVC)
3149
target_link_libraries(${PROJECT_NAME} PUBLIC
32-
pthread
33-
$<$<NOT:$<STREQUAL:${CMAKE_SYSTEM_NAME},Windows>>:rt>)
50+
pthread
51+
$<$<NOT:$<STREQUAL:${CMAKE_SYSTEM_NAME},Windows>>:rt>)
3452
endif()
3553

3654
install(
3755
TARGETS ${PROJECT_NAME}
38-
DESTINATION "lib"
56+
RUNTIME DESTINATION bin
57+
LIBRARY DESTINATION lib
58+
ARCHIVE DESTINATION lib
3959
)

0 commit comments

Comments
 (0)