Skip to content

Commit 3c7e94a

Browse files
committed
modify cmakelists options
1 parent c9d92b5 commit 3c7e94a

File tree

8 files changed

+32
-85
lines changed

8 files changed

+32
-85
lines changed

.gitignore

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

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

3rdparty/gtest/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ option(
2525
gtest_hide_internal_symbols
2626
"Build gtest with internal symbols hidden in shared libraries."
2727
OFF)
28-
29-
if (MSVC AND USE_STATIC_CRT)
30-
set(CompilerFlags
31-
CMAKE_CXX_FLAGS
32-
CMAKE_CXX_FLAGS_DEBUG
33-
CMAKE_CXX_FLAGS_RELEASE
34-
CMAKE_C_FLAGS
35-
CMAKE_C_FLAGS_DEBUG
36-
CMAKE_C_FLAGS_RELEASE
37-
)
38-
foreach(CompilerFlag ${CompilerFlags})
39-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
40-
endforeach()
41-
endif()
4228

4329
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
4430
include(cmake/hermetic_build.cmake OPTIONAL)

CMakeLists.txt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.12)
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)
6-
option(USE_STATIC_CRT "Set to ON to build with static CRT on Windows (/MT)." 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)." ON )
78

89
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
910
set(CMAKE_CXX_STANDARD 17)
@@ -12,19 +13,32 @@ if(NOT MSVC)
1213
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
1314
endif()
1415

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()
29+
1530
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
1631
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
17-
1832
set(LIBIPC_PROJECT_DIR ${PROJECT_SOURCE_DIR})
1933

20-
2134
# Unicode Support
2235
add_definitions(-DUNICODE -D_UNICODE)
2336

2437
add_subdirectory(src)
2538

2639
if (LIBIPC_BUILD_TESTS)
2740
set(GOOGLETEST_VERSION 1.10.0)
41+
set(gtest_force_shared_crt $<NOT:$<BOOL:${LIBIPC_USE_STATIC_CRT}>>)
2842
add_subdirectory(3rdparty/gtest)
2943
add_subdirectory(test)
3044
endif()

demo/chat/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
project(chat)
22

3-
if (MSVC AND USE_STATIC_CRT)
4-
set(CompilerFlags
5-
CMAKE_CXX_FLAGS
6-
CMAKE_CXX_FLAGS_DEBUG
7-
CMAKE_CXX_FLAGS_RELEASE
8-
CMAKE_C_FLAGS
9-
CMAKE_C_FLAGS_DEBUG
10-
CMAKE_C_FLAGS_RELEASE
11-
)
12-
foreach(CompilerFlag ${CompilerFlags})
13-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
14-
endforeach()
15-
endif()
16-
173
file(GLOB SRC_FILES ./*.cpp)
184
file(GLOB HEAD_FILES ./*.h)
195

demo/msg_que/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
project(msg_que)
22

3-
if (MSVC AND USE_STATIC_CRT)
4-
set(CompilerFlags
5-
CMAKE_CXX_FLAGS
6-
CMAKE_CXX_FLAGS_DEBUG
7-
CMAKE_CXX_FLAGS_RELEASE
8-
CMAKE_C_FLAGS
9-
CMAKE_C_FLAGS_DEBUG
10-
CMAKE_C_FLAGS_RELEASE
11-
)
12-
foreach(CompilerFlag ${CompilerFlags})
13-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
14-
endforeach()
15-
endif()
16-
173
include_directories(
184
${LIBIPC_PROJECT_DIR}/3rdparty)
195

src/CMakeLists.txt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
project(ipc)
2-
3-
option(LIBIPC_BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
4-
5-
if (MSVC AND USE_STATIC_CRT)
6-
set(CompilerFlags
7-
CMAKE_CXX_FLAGS
8-
CMAKE_CXX_FLAGS_DEBUG
9-
CMAKE_CXX_FLAGS_RELEASE
10-
CMAKE_C_FLAGS
11-
CMAKE_C_FLAGS_DEBUG
12-
CMAKE_C_FLAGS_RELEASE
13-
)
14-
foreach(CompilerFlag ${CompilerFlags})
15-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
16-
endforeach()
17-
endif()
1+
project(ipc VERSION 1.0.0 LANGUAGES CXX)
182

193
if(UNIX)
204
file(GLOB SRC_FILES ${LIBIPC_PROJECT_DIR}/src/libipc/platform/*_linux.cpp)
@@ -43,7 +27,7 @@ else()
4327
add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES})
4428
endif()
4529

46-
# Set output directory
30+
# set output directory
4731
set_target_properties(${PROJECT_NAME}
4832
PROPERTIES
4933
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"

test/CMakeLists.txt

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

3-
if (MSVC AND USE_STATIC_CRT)
4-
set(CompilerFlags
5-
CMAKE_CXX_FLAGS
6-
CMAKE_CXX_FLAGS_DEBUG
7-
CMAKE_CXX_FLAGS_RELEASE
8-
CMAKE_C_FLAGS
9-
CMAKE_C_FLAGS_DEBUG
10-
CMAKE_C_FLAGS_RELEASE
11-
)
12-
foreach(CompilerFlag ${CompilerFlags})
13-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
14-
endforeach()
15-
endif()
16-
173
if(NOT MSVC)
184
add_compile_options(
195
-Wno-attributes

test/test_platform.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
#include "libipc/platform/to_tchar.h"
1111

1212
TEST(Platform, to_tchar) {
13-
char const utf8[] = {
13+
unsigned char const utf8[] = {
1414
0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2c, 0x20, 0xe6, 0xb5, 0xa3,
1515
0xe7, 0x8a, 0xb2, 0xe3, 0x82, 0xbd, 0xe9, 0x94, 0x9b, 0xe5, 0xb1, 0xbb, 0xe4, 0xba, 0xbe, 0xe9,
1616
0x8a, 0x88, 0xe6, 0x92, 0xb1, 0xe4, 0xbc, 0x80, 0xe9, 0x8a, 0x87, 0xc2, 0xb0, 0xe4, 0xbc, 0x85,
1717
0x00,
1818
};
19-
wchar_t const wstr[] = L"hello world, 你好,こんにちは";
19+
char const *sstr = reinterpret_cast<char const *>(utf8);
20+
wchar_t const *wstr = reinterpret_cast<wchar_t const *>(u"hello world, 你好,こんにちは");
2021
{
21-
ipc::string str = ipc::detail::to_tchar<char>(utf8);
22-
EXPECT_STREQ(str.c_str(), utf8);
22+
ipc::string str = ipc::detail::to_tchar<char>(sstr);
23+
EXPECT_STREQ(str.c_str(), sstr);
2324
}
2425
{
25-
ipc::wstring wtr = ipc::detail::to_tchar<wchar_t>(utf8);
26+
ipc::wstring wtr = ipc::detail::to_tchar<wchar_t>(sstr);
2627
EXPECT_STREQ(wtr.c_str(), wstr);
2728
}
2829
}

0 commit comments

Comments
 (0)