Skip to content

Commit 37fb91e

Browse files
committed
Fix Windows build
1 parent cec3dcb commit 37fb91e

12 files changed

+70
-43
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
2121

2222
add_compile_definitions(MODULE_NAME="cppbase")
2323

24+
if (MSVC)
25+
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
26+
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
27+
28+
# -DWIN32_LEAN_AND_MEAN is for winsock.h has already been included error
29+
# -D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING is for warning STL4009
30+
# std::allocator<void> is deprecated in C++17
31+
add_definitions(
32+
-D_WIN32_WINNT=0x0A00
33+
-DNOMINMAX
34+
-DWIN32_LEAN_AND_MEAN
35+
-D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING
36+
-D_CRT_SECURE_NO_WARNINGS)
37+
endif()
38+
2439
enable_testing()
2540

2641
add_subdirectory(thirdparty)

CMakeSettings.json

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
{
2-
// 请参阅 https://go.microsoft.com//fwlink//?linkid=834763 了解有关此文件的详细信息。
3-
"configurations": [
4-
{
5-
"name": "x64-Debug",
6-
"generator": "Ninja",
7-
"configurationType": "Debug",
8-
"inheritEnvironments": [ "msvc_x64_x64" ],
9-
"buildRoot": "${projectDir}\\vs2017\\build\\${name}",
10-
"installRoot": "${projectDir}\\vs2017\\install\\${name}",
11-
"cmakeCommandArgs": "",
12-
"buildCommandArgs": "-v",
13-
"ctestCommandArgs": ""
14-
},
15-
{
16-
"name": "x64-Release",
17-
"generator": "Ninja",
18-
"configurationType": "RelWithDebInfo",
19-
"inheritEnvironments": [ "msvc_x64_x64" ],
20-
"buildRoot": "${projectDir}\\vs2017\\build\\${name}",
21-
"installRoot": "${projectDir}\\vs2017\\install\\${name}",
22-
"cmakeCommandArgs": "",
23-
"buildCommandArgs": "-v",
24-
"ctestCommandArgs": ""
25-
}
26-
]
1+
{
2+
"configurations": [
3+
{
4+
"name": "x64-Debug",
5+
"generator": "Ninja",
6+
"configurationType": "Debug",
7+
"inheritEnvironments": [
8+
"msvc_x64_x64"
9+
],
10+
"buildRoot": "${projectDir}\\build\\${name}",
11+
"installRoot": "${projectDir}\\install\\${name}",
12+
"cmakeCommandArgs": "",
13+
"buildCommandArgs": "-v",
14+
"ctestCommandArgs": ""
15+
},
16+
{
17+
"name": "x64-Release",
18+
"generator": "Ninja",
19+
"configurationType": "Release",
20+
"inheritEnvironments": [
21+
"msvc_x64_x64"
22+
],
23+
"buildRoot": "${projectDir}\\build\\${name}",
24+
"installRoot": "${projectDir}\\install\\${name}",
25+
"cmakeCommandArgs": "",
26+
"buildCommandArgs": "-v",
27+
"ctestCommandArgs": ""
28+
}
29+
]
2730
}

common/MemoryLeaks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#endif
2020

2121
#if defined(_MSC_VER)
22-
#define VLD_FORCE_ENABLE
23-
#include <vld.h>
22+
// #define VLD_FORCE_ENABLE
23+
// #include <vld.h>
2424
#endif
2525

2626
// See tests/common/MemoryLeaksTests.cpp for examples

common/ThreadPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DLLEXPORT ThreadPool
5959
* the thread affinity for the 4 threads in the thread pool will be
6060
* set to CPU1, CPU2, CPU3, CPU1, and CPU0 is not used.
6161
*/
62-
ThreadPool(uint32_t threads, ThreadPriority priority, uint32_t cpu_reserved = 0);
62+
explicit ThreadPool(uint32_t threads, ThreadPriority priority, uint32_t cpu_reserved = 0);
6363
~ThreadPool();
6464

6565
template<class F, class... Args>

common/ThreadPool_intl.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace cppbase {
1414

15+
static auto logger = logging::GetLoggerForCurrentModule();
16+
1517
// #ifdef __linux__
1618
#if 0
1719
int32_t SetThreadPriority(ThreadPriority priority)
@@ -67,7 +69,7 @@ int32_t SetThreadPriority(ThreadPriority)
6769
return 0;
6870
}
6971

70-
int32_t GetThreadPriority(ino64_t)
72+
int32_t GetThreadPriority(int64_t)
7173
{
7274
return 0;
7375
}
@@ -83,6 +85,7 @@ ThreadPool::ThreadPool(uint32_t threads, ThreadPriority priority, uint32_t cpu_r
8385
auto set_affinity = [&](uint32_t index, std::thread& thread) {
8486
if (cpu_reserved && cpu_reserved < cpu_nums)
8587
{
88+
#ifdef __linux__
8689
uint32_t cpu_id = index % (cpu_nums - cpu_reserved);
8790
cpu_set_t cpuset;
8891
CPU_ZERO(&cpuset);
@@ -91,8 +94,9 @@ ThreadPool::ThreadPool(uint32_t threads, ThreadPriority priority, uint32_t cpu_r
9194
sizeof(cpu_set_t), &cpuset);
9295
if (rc != 0)
9396
{
94-
// olog_error("ThreadPool", "Error calling pthread_setaffinity_np: {}", rc);
97+
logger->error("Error calling pthread_setaffinity_np: {}", rc);
9598
}
99+
#endif
96100
}
97101
};
98102

@@ -116,9 +120,8 @@ ThreadPool::ThreadPool(uint32_t threads, ThreadPriority priority, uint32_t cpu_r
116120
});
117121
set_affinity(i, m_threads[i]);
118122
}
119-
// olog_info("ThreadPool",
120-
// "Created thread pool with {} threads at priority {}, {} CPU core(s) reserved",
121-
// threads, priority, cpu_reserved);
123+
logger->info("Created thread pool with {} threads at priority {}, {} CPU core(s) reserved",
124+
threads, priority, cpu_reserved);
122125
}
123126

124127
// the destructor joins all threads

logging/Logging_intl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Instance
2424
fs::path log_conf = fs::path(filesystem::GetConfigDir())/filesystem::LogConfigFilename;
2525
if (fs::exists(log_conf))
2626
{
27-
spdlog_setup::from_file(log_conf.c_str());
27+
spdlog_setup::from_file(log_conf.generic_string());
2828
}
2929
else
3030
{

tests/common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ target_include_directories(common_test PUBLIC
1717
$<INSTALL_INTERFACE:include>
1818
)
1919

20-
set_target_warnings_as_error(TARGET common_test)
20+
# set_target_warnings_as_error(TARGET common_test)
2121
target_compile_features(common_test PRIVATE ${CXX_STD})
2222

2323
target_link_libraries(common_test gtest spdlog)

tests/common/FlagsTests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TEST(FlagsTests, FlagsTests)
2727
{
2828
// build flags
2929
FooFlags flags{FooFlag::FLAG_A, FooFlag::FLAG_B, FooFlag::FLAG_C};
30-
EXPECT_EQ(flags, 0x1 | 0x2 | 0x4);
30+
EXPECT_EQ(static_cast<int>(flags), 0x1 | 0x2 | 0x4);
3131

3232
// check flags
3333
EXPECT_TRUE(flags & FooFlag::FLAG_A);
@@ -44,9 +44,9 @@ TEST(FlagsTests, FlagsTests)
4444
flags.SetFlag(FooFlag::FLAG_D, false); // set D off
4545
EXPECT_FALSE(flags & FooFlag::FLAG_D);
4646
flags.SetFlags({FooFlag::FLAG_A, FooFlag::FLAG_B}, false); // set A/B off
47-
EXPECT_EQ(flags, 0x4);
47+
EXPECT_EQ(static_cast<int>(flags), 0x4);
4848
flags |= {FooFlag::FLAG_E, FooFlag::FLAG_F}; // set E/F on
49-
EXPECT_EQ(flags, 0x4 | 0x10 | 0x20);
49+
EXPECT_EQ(static_cast<int>(flags), 0x4 | 0x10 | 0x20);
5050
flags &= ~FooFlags{FooFlag::FLAG_E, FooFlag::FLAG_F}; // set E/F off
51-
EXPECT_EQ(flags, 0x4);
51+
EXPECT_EQ(static_cast<int>(flags), 0x4);
5252
}

tests/common/ThreadPoolTests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ TEST(ThreadPoolTests, SimpleTest)
2121
for(int32_t i = 0; i < 8; ++i)
2222
{
2323
results.emplace_back(pool.Enqueue([i] {
24+
#ifdef __linux__
2425
std::cout << "ThreadPoolTests::SimpleTest thread=" << i
2526
<< " running on CPU=" << sched_getcpu() << std::endl;
27+
#endif
2628
std::this_thread::sleep_for(std::chrono::seconds(1));
2729
return i*i;
2830
}));
@@ -45,8 +47,10 @@ TEST(ThreadPoolTests, PriorityAndCpuTest)
4547
for(int32_t i = 0; i < 8; ++i)
4648
{
4749
results.emplace_back(pool.Enqueue([i] {
50+
#ifdef __linux__
4851
std::cout << "ThreadPoolTests::PriorityAndCpuTest thread=" << i
4952
<< " running on CPU=" << sched_getcpu() << std::endl;
53+
#endif
5054
std::this_thread::sleep_for(std::chrono::seconds(1));
5155
return i*i;
5256
}));

tests/logging/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ target_include_directories(logging_test PUBLIC
1313
$<INSTALL_INTERFACE:include>
1414
)
1515

16-
set_target_warnings_as_error(TARGET logging_test)
16+
# set_target_warnings_as_error(TARGET logging_test)
1717
target_compile_features(logging_test PRIVATE ${CXX_STD})
1818

1919
target_link_libraries(logging_test gtest spdlog)

thirdparty/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ add_subdirectory(${sigslot_SOURCE_DIR} ${sigslot_BINARY_DIR})
9898
# spdlog
9999
# ============================================================
100100
#
101+
set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "")
101102
download_project(
102103
PROJ spdlog
103104
URL ${CMAKE_CURRENT_SOURCE_DIR}/spdlog/v1.8.2.tar.gz
@@ -119,15 +120,16 @@ download_project(
119120
add_library(stduuid INTERFACE)
120121
target_include_directories(stduuid INTERFACE ${stduuid_SOURCE_DIR}/include)
121122

122-
if (MSVC)
123+
if (FALSE)
123124
# ============================================================
124125
# vld
125126
# ============================================================
126127
#
128+
set(VLD_FMT_EXTERNAL ON CACHE BOOL "")
127129
download_project(
128130
PROJ vld
129131
URL ${CMAKE_CURRENT_SOURCE_DIR}/vld/2.5.2.tar.gz
130-
URL_HASH MD5=44d2edc7e006b97be4bdf43de7b5f3b5
132+
URL_HASH MD5=daa96b5e7427411ba7258fcf8e72df92
131133
QUIET
132134
)
133135
add_subdirectory(${vld_SOURCE_DIR} ${vld_BINARY_DIR})

thirdparty/vld/2.5.2.tar.gz

-642 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)