From 3c7e94a167e8dbdd759aea7554bf7b96c5505174 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 15 Aug 2021 13:23:43 +0800 Subject: [PATCH] modify cmakelists options --- .gitignore | 4 ++++ 3rdparty/gtest/CMakeLists.txt | 14 -------------- CMakeLists.txt | 26 ++++++++++++++++++++------ demo/chat/CMakeLists.txt | 14 -------------- demo/msg_que/CMakeLists.txt | 14 -------------- src/CMakeLists.txt | 20 ++------------------ test/CMakeLists.txt | 14 -------------- test/test_platform.cpp | 11 ++++++----- 8 files changed, 32 insertions(+), 85 deletions(-) diff --git a/.gitignore b/.gitignore index 5ea6006..9bca061 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,7 @@ CMakeLists.txt.user* # My output files build + +# vs +.vs +.vscode \ No newline at end of file diff --git a/3rdparty/gtest/CMakeLists.txt b/3rdparty/gtest/CMakeLists.txt index 68de47c..77f0b58 100644 --- a/3rdparty/gtest/CMakeLists.txt +++ b/3rdparty/gtest/CMakeLists.txt @@ -25,20 +25,6 @@ option( gtest_hide_internal_symbols "Build gtest with internal symbols hidden in shared libraries." OFF) - -if (MSVC AND USE_STATIC_CRT) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() -endif() # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). include(cmake/hermetic_build.cmake OPTIONAL) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5399a90..3d6143d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,10 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(cpp-ipc) -option(LIBIPC_BUILD_TESTS "Build all of libipc's own tests." OFF) -option(LIBIPC_BUILD_DEMOS "Build all of libipc's own demos." OFF) -option(USE_STATIC_CRT "Set to ON to build with static CRT on Windows (/MT)." OFF) +option(LIBIPC_BUILD_TESTS "Build all of libipc's own tests." OFF) +option(LIBIPC_BUILD_DEMOS "Build all of libipc's own demos." OFF) +option(LIBIPC_BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) +option(LIBIPC_USE_STATIC_CRT "Set to ON to build with static CRT on Windows (/MT)." ON ) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_CXX_STANDARD 17) @@ -12,12 +13,24 @@ if(NOT MSVC) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() +if (MSVC AND LIBIPC_USE_STATIC_CRT) + set(CompilerFlags + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_RELEASE + ) + foreach(CompilerFlag ${CompilerFlags}) + string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") + endforeach() +endif() + set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) - set(LIBIPC_PROJECT_DIR ${PROJECT_SOURCE_DIR}) - # Unicode Support add_definitions(-DUNICODE -D_UNICODE) @@ -25,6 +38,7 @@ add_subdirectory(src) if (LIBIPC_BUILD_TESTS) set(GOOGLETEST_VERSION 1.10.0) + set(gtest_force_shared_crt $>) add_subdirectory(3rdparty/gtest) add_subdirectory(test) endif() diff --git a/demo/chat/CMakeLists.txt b/demo/chat/CMakeLists.txt index 77850c9..c5bcea8 100755 --- a/demo/chat/CMakeLists.txt +++ b/demo/chat/CMakeLists.txt @@ -1,19 +1,5 @@ project(chat) -if (MSVC AND USE_STATIC_CRT) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() -endif() - file(GLOB SRC_FILES ./*.cpp) file(GLOB HEAD_FILES ./*.h) diff --git a/demo/msg_que/CMakeLists.txt b/demo/msg_que/CMakeLists.txt index 65ce4d3..da0de71 100755 --- a/demo/msg_que/CMakeLists.txt +++ b/demo/msg_que/CMakeLists.txt @@ -1,19 +1,5 @@ project(msg_que) -if (MSVC AND USE_STATIC_CRT) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() -endif() - include_directories( ${LIBIPC_PROJECT_DIR}/3rdparty) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b80a2aa..cd49b02 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,20 +1,4 @@ -project(ipc) - -option(LIBIPC_BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) - -if (MSVC AND USE_STATIC_CRT) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() -endif() +project(ipc VERSION 1.0.0 LANGUAGES CXX) if(UNIX) file(GLOB SRC_FILES ${LIBIPC_PROJECT_DIR}/src/libipc/platform/*_linux.cpp) @@ -43,7 +27,7 @@ else() add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES}) endif() -# Set output directory +# set output directory set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6be27af..4b695eb 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,19 +1,5 @@ project(test-ipc) -if (MSVC AND USE_STATIC_CRT) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() -endif() - if(NOT MSVC) add_compile_options( -Wno-attributes diff --git a/test/test_platform.cpp b/test/test_platform.cpp index c368690..4a49309 100644 --- a/test/test_platform.cpp +++ b/test/test_platform.cpp @@ -10,19 +10,20 @@ #include "libipc/platform/to_tchar.h" TEST(Platform, to_tchar) { - char const utf8[] = { + unsigned char const utf8[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2c, 0x20, 0xe6, 0xb5, 0xa3, 0xe7, 0x8a, 0xb2, 0xe3, 0x82, 0xbd, 0xe9, 0x94, 0x9b, 0xe5, 0xb1, 0xbb, 0xe4, 0xba, 0xbe, 0xe9, 0x8a, 0x88, 0xe6, 0x92, 0xb1, 0xe4, 0xbc, 0x80, 0xe9, 0x8a, 0x87, 0xc2, 0xb0, 0xe4, 0xbc, 0x85, 0x00, }; - wchar_t const wstr[] = L"hello world, 你好,こんにちは"; + char const *sstr = reinterpret_cast(utf8); + wchar_t const *wstr = reinterpret_cast(u"hello world, 你好,こんにちは"); { - ipc::string str = ipc::detail::to_tchar(utf8); - EXPECT_STREQ(str.c_str(), utf8); + ipc::string str = ipc::detail::to_tchar(sstr); + EXPECT_STREQ(str.c_str(), sstr); } { - ipc::wstring wtr = ipc::detail::to_tchar(utf8); + ipc::wstring wtr = ipc::detail::to_tchar(sstr); EXPECT_STREQ(wtr.c_str(), wstr); } }