modify cmakelists options

This commit is contained in:
mutouyun 2021-08-15 13:23:43 +08:00
parent c9d92b5364
commit 3c7e94a167
8 changed files with 32 additions and 85 deletions

4
.gitignore vendored
View File

@ -44,3 +44,7 @@ CMakeLists.txt.user*
# My output files # My output files
build build
# vs
.vs
.vscode

View File

@ -26,20 +26,6 @@ option(
"Build gtest with internal symbols hidden in shared libraries." "Build gtest with internal symbols hidden in shared libraries."
OFF) 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(). # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
include(cmake/hermetic_build.cmake OPTIONAL) include(cmake/hermetic_build.cmake OPTIONAL)

View File

@ -1,9 +1,10 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.12)
project(cpp-ipc) project(cpp-ipc)
option(LIBIPC_BUILD_TESTS "Build all of libipc's own tests." 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_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_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_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
@ -12,12 +13,24 @@ if(NOT MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
endif() 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(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBIPC_PROJECT_DIR ${PROJECT_SOURCE_DIR}) set(LIBIPC_PROJECT_DIR ${PROJECT_SOURCE_DIR})
# Unicode Support # Unicode Support
add_definitions(-DUNICODE -D_UNICODE) add_definitions(-DUNICODE -D_UNICODE)
@ -25,6 +38,7 @@ add_subdirectory(src)
if (LIBIPC_BUILD_TESTS) if (LIBIPC_BUILD_TESTS)
set(GOOGLETEST_VERSION 1.10.0) set(GOOGLETEST_VERSION 1.10.0)
set(gtest_force_shared_crt $<NOT:$<BOOL:${LIBIPC_USE_STATIC_CRT}>>)
add_subdirectory(3rdparty/gtest) add_subdirectory(3rdparty/gtest)
add_subdirectory(test) add_subdirectory(test)
endif() endif()

View File

@ -1,19 +1,5 @@
project(chat) 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 SRC_FILES ./*.cpp)
file(GLOB HEAD_FILES ./*.h) file(GLOB HEAD_FILES ./*.h)

View File

@ -1,19 +1,5 @@
project(msg_que) 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( include_directories(
${LIBIPC_PROJECT_DIR}/3rdparty) ${LIBIPC_PROJECT_DIR}/3rdparty)

View File

@ -1,20 +1,4 @@
project(ipc) project(ipc VERSION 1.0.0 LANGUAGES CXX)
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()
if(UNIX) if(UNIX)
file(GLOB SRC_FILES ${LIBIPC_PROJECT_DIR}/src/libipc/platform/*_linux.cpp) 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}) add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES})
endif() endif()
# Set output directory # set output directory
set_target_properties(${PROJECT_NAME} set_target_properties(${PROJECT_NAME}
PROPERTIES PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"

View File

@ -1,19 +1,5 @@
project(test-ipc) 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) if(NOT MSVC)
add_compile_options( add_compile_options(
-Wno-attributes -Wno-attributes

View File

@ -10,19 +10,20 @@
#include "libipc/platform/to_tchar.h" #include "libipc/platform/to_tchar.h"
TEST(Platform, to_tchar) { 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, 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, 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, 0x8a, 0x88, 0xe6, 0x92, 0xb1, 0xe4, 0xbc, 0x80, 0xe9, 0x8a, 0x87, 0xc2, 0xb0, 0xe4, 0xbc, 0x85,
0x00, 0x00,
}; };
wchar_t const wstr[] = L"hello world, 你好,こんにちは"; char const *sstr = reinterpret_cast<char const *>(utf8);
wchar_t const *wstr = reinterpret_cast<wchar_t const *>(u"hello world, 你好,こんにちは");
{ {
ipc::string str = ipc::detail::to_tchar<char>(utf8); ipc::string str = ipc::detail::to_tchar<char>(sstr);
EXPECT_STREQ(str.c_str(), utf8); EXPECT_STREQ(str.c_str(), sstr);
} }
{ {
ipc::wstring wtr = ipc::detail::to_tchar<wchar_t>(utf8); ipc::wstring wtr = ipc::detail::to_tchar<wchar_t>(sstr);
EXPECT_STREQ(wtr.c_str(), wstr); EXPECT_STREQ(wtr.c_str(), wstr);
} }
} }