From 38b23fd56596cdc4113cf41facbe9a936f10f7a3 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Thu, 2 Sep 2021 15:27:23 +0800 Subject: [PATCH 1/4] Pass build on windows --- CMakeLists.txt | 9 ++++++++- async_udp_client/CMakeLists.txt | 2 +- custom_errorcode/CMakeLists.txt | 2 +- custom_timer_manager/CMakeLists.txt | 2 +- executor/CMakeLists.txt | 2 +- fixed-size-package/CMakeLists.txt | 4 ++-- httpclient-https/CMakeLists.txt | 3 +-- httpclient/CMakeLists.txt | 2 +- io_context/CMakeLists.txt | 2 +- redis-asio/CMakeLists.txt | 6 +++--- redis-asio/response_parser.cpp | 3 ++- simplest_httpsvr/CMakeLists.txt | 2 +- timer-performance/CMakeLists.txt | 2 +- timer_usage/CMakeLists.txt | 4 ++-- 14 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11f9fd8..81ffb16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,14 @@ cmake_minimum_required(VERSION 3.19) project(network) -set(CMAKE_CXX_FLAGS "-g -O2 -std=c++11 -DASIO_STANDALONE -Werror") +set(CMAKE_CXX_STANDARD 17) +add_compile_options("-DASIO_STANDALONE") + +if (MSVC) + add_compile_options("/EHsc") +else() + add_compile_options("-g -O2 -Werror") +endif() set(ASIO_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/asio/asio/include) set(CATCH_SINGLE_INCLUDE ${PROJECT_SOURCE_DIR}/3rdparty/unit_test) # for unit test diff --git a/async_udp_client/CMakeLists.txt b/async_udp_client/CMakeLists.txt index 70c6233..b572e4a 100644 --- a/async_udp_client/CMakeLists.txt +++ b/async_udp_client/CMakeLists.txt @@ -5,4 +5,4 @@ add_executable(async_udp_client async_udp_client_test.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(async_udp_client PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(async_udp_client pthread) \ No newline at end of file +target_link_libraries(async_udp_client ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/custom_errorcode/CMakeLists.txt b/custom_errorcode/CMakeLists.txt index 4fa9606..f482324 100644 --- a/custom_errorcode/CMakeLists.txt +++ b/custom_errorcode/CMakeLists.txt @@ -5,4 +5,4 @@ add_executable(custom_errorcode custom-error-code.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(custom_errorcode PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(custom_errorcode pthread) \ No newline at end of file +target_link_libraries(custom_errorcode ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/custom_timer_manager/CMakeLists.txt b/custom_timer_manager/CMakeLists.txt index 6259102..718acf4 100644 --- a/custom_timer_manager/CMakeLists.txt +++ b/custom_timer_manager/CMakeLists.txt @@ -5,4 +5,4 @@ add_executable(custom_timer_mgr custom_timer_mgr.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(custom_timer_mgr PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(custom_timer_mgr pthread) \ No newline at end of file +target_link_libraries(custom_timer_mgr ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/executor/CMakeLists.txt b/executor/CMakeLists.txt index 715c229..53cd081 100644 --- a/executor/CMakeLists.txt +++ b/executor/CMakeLists.txt @@ -5,4 +5,4 @@ add_executable(executor_basic basic_usage.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(executor_basic PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(executor_basic pthread) \ No newline at end of file +target_link_libraries(executor_basic ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/fixed-size-package/CMakeLists.txt b/fixed-size-package/CMakeLists.txt index ceecbca..ccb0730 100644 --- a/fixed-size-package/CMakeLists.txt +++ b/fixed-size-package/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable(fixed-size-client client.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(fixed-size-server PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(fixed-size-server pthread) +target_link_libraries(fixed-size-server ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(fixed-size-client PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(fixed-size-client pthread) \ No newline at end of file +target_link_libraries(fixed-size-client ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/httpclient-https/CMakeLists.txt b/httpclient-https/CMakeLists.txt index 18ae4ca..7b4b936 100644 --- a/httpclient-https/CMakeLists.txt +++ b/httpclient-https/CMakeLists.txt @@ -4,6 +4,5 @@ cmake_minimum_required(VERSION 2.8) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) add_executable(${PROJECT_NAME} https-client.cpp AsyncHttpsClient.cpp) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} pthread ssl crypto) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ssl crypto) target_include_directories(${PROJECT_NAME} PUBLIC ${ASIO_INCLUDE_DIR} /usr/local/Cellar/openssl/1.0.2o_1/include) - diff --git a/httpclient/CMakeLists.txt b/httpclient/CMakeLists.txt index cb5577d..c63c1e0 100644 --- a/httpclient/CMakeLists.txt +++ b/httpclient/CMakeLists.txt @@ -3,6 +3,6 @@ project(http_client) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) add_executable(${PROJECT_NAME} http_client.cpp AsyncHttpClient.cpp) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} pthread) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${PROJECT_NAME} PUBLIC ${ASIO_INCLUDE_DIR}) diff --git a/io_context/CMakeLists.txt b/io_context/CMakeLists.txt index 5568876..28e435e 100644 --- a/io_context/CMakeLists.txt +++ b/io_context/CMakeLists.txt @@ -5,4 +5,4 @@ add_executable(io_context_usage io_context_usage.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(io_context_usage PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(io_context_usage pthread) \ No newline at end of file +target_link_libraries(io_context_usage ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/redis-asio/CMakeLists.txt b/redis-asio/CMakeLists.txt index 3562328..c2111fa 100644 --- a/redis-asio/CMakeLists.txt +++ b/redis-asio/CMakeLists.txt @@ -7,10 +7,10 @@ add_executable(protocol_parser_test response_parser.cpp response_parser_test.cpp set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(mt-redis-cli PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(mt-redis-cli pthread) +target_link_libraries(mt-redis-cli ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(general-redis-cli PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(general-redis-cli pthread) +target_link_libraries(general-redis-cli ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(protocol_parser_test PRIVATE ${ASIO_INCLUDE_DIR} ${CATCH_SINGLE_INCLUDE}) -target_link_libraries(protocol_parser_test pthread) \ No newline at end of file +target_link_libraries(protocol_parser_test ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/redis-asio/response_parser.cpp b/redis-asio/response_parser.cpp index f33bc89..95e50cd 100644 --- a/redis-asio/response_parser.cpp +++ b/redis-asio/response_parser.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "response_parser.h" @@ -136,7 +137,7 @@ ParseResult BulkString::Feed(char c) switch (status_) { case BULK_STATUS::BS_EXPECT_LENGTH: - if (c == '-' or std::isdigit(c)) + if (c == '-' || std::isdigit(c)) { length_line_.push_back(c); } diff --git a/simplest_httpsvr/CMakeLists.txt b/simplest_httpsvr/CMakeLists.txt index d80d0bd..155dcb2 100644 --- a/simplest_httpsvr/CMakeLists.txt +++ b/simplest_httpsvr/CMakeLists.txt @@ -3,4 +3,4 @@ project(simplest-httpsvr) add_executable(simplest-httpsvr http_svr.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(simplest-httpsvr PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(simplest-httpsvr pthread) +target_link_libraries(simplest-httpsvr ${CMAKE_THREAD_LIBS_INIT}) diff --git a/timer-performance/CMakeLists.txt b/timer-performance/CMakeLists.txt index 8b060d8..53252b3 100644 --- a/timer-performance/CMakeLists.txt +++ b/timer-performance/CMakeLists.txt @@ -5,4 +5,4 @@ add_executable(tp main.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(tp PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(tp pthread) \ No newline at end of file +target_link_libraries(tp ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file diff --git a/timer_usage/CMakeLists.txt b/timer_usage/CMakeLists.txt index 63451c4..821ab68 100644 --- a/timer_usage/CMakeLists.txt +++ b/timer_usage/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable(timer_repeated repeated.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(timer_basic PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(timer_basic pthread) +target_link_libraries(timer_basic ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(timer_repeated PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(timer_repeated pthread) \ No newline at end of file +target_link_libraries(timer_repeated ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file From a14445ca1ebe25381e07924a7fb7703ff3f7723f Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Thu, 2 Sep 2021 15:54:44 +0800 Subject: [PATCH 2/4] Buildfix --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81ffb16..608b04a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,13 +2,13 @@ cmake_minimum_required(VERSION 3.19) project(network) -set(CMAKE_CXX_STANDARD 17) -add_compile_options("-DASIO_STANDALONE") +set(CMAKE_CXX_STANDARD 14) +add_compile_options(-DASIO_STANDALONE) if (MSVC) - add_compile_options("/EHsc") + add_compile_options(/EHsc) else() - add_compile_options("-g -O2 -Werror") + add_compile_options(-g -O2 -Werror) endif() set(ASIO_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/asio/asio/include) From 2b535cb23dcb409aaab1437dd85eb841b58dac82 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Fri, 3 Sep 2021 09:32:41 +0800 Subject: [PATCH 3/4] Add a macro _WIN32_WINNT to suppress the warnings on windows --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 608b04a..2c953ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ add_compile_options(-DASIO_STANDALONE) if (MSVC) add_compile_options(/EHsc) + add_compile_definitions(_WIN32_WINNT=0x0A00) else() add_compile_options(-g -O2 -Werror) endif() From 2f2d6d4a290e453fe95034643bdea28bd6471f42 Mon Sep 17 00:00:00 2001 From: Jun Chen Date: Mon, 6 Sep 2021 18:51:24 +0800 Subject: [PATCH 4/4] Build fix on linux --- async_udp_client/CMakeLists.txt | 5 ++++- custom_errorcode/CMakeLists.txt | 5 ++++- custom_timer_manager/CMakeLists.txt | 5 ++++- executor/CMakeLists.txt | 5 ++++- fixed-size-package/CMakeLists.txt | 7 +++++-- httpclient-https/CMakeLists.txt | 7 +++++-- httpclient/CMakeLists.txt | 6 ++++-- io_context/CMakeLists.txt | 5 ++++- redis-asio/CMakeLists.txt | 9 ++++++--- simplest_httpsvr/CMakeLists.txt | 5 ++++- timer-performance/CMakeLists.txt | 5 ++++- timer_usage/CMakeLists.txt | 7 +++++-- 12 files changed, 53 insertions(+), 18 deletions(-) diff --git a/async_udp_client/CMakeLists.txt b/async_udp_client/CMakeLists.txt index b572e4a..d9e3f6f 100644 --- a/async_udp_client/CMakeLists.txt +++ b/async_udp_client/CMakeLists.txt @@ -1,8 +1,11 @@ project(async_udp_client) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(async_udp_client async_udp_client_test.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(async_udp_client PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(async_udp_client ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(async_udp_client Threads::Threads) \ No newline at end of file diff --git a/custom_errorcode/CMakeLists.txt b/custom_errorcode/CMakeLists.txt index f482324..d3683ac 100644 --- a/custom_errorcode/CMakeLists.txt +++ b/custom_errorcode/CMakeLists.txt @@ -1,8 +1,11 @@ project(custom_errorcode) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(custom_errorcode custom-error-code.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(custom_errorcode PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(custom_errorcode ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(custom_errorcode Threads::Threads) \ No newline at end of file diff --git a/custom_timer_manager/CMakeLists.txt b/custom_timer_manager/CMakeLists.txt index 718acf4..706edf6 100644 --- a/custom_timer_manager/CMakeLists.txt +++ b/custom_timer_manager/CMakeLists.txt @@ -1,8 +1,11 @@ project(custom_timer_mgr) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(custom_timer_mgr custom_timer_mgr.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(custom_timer_mgr PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(custom_timer_mgr ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(custom_timer_mgr Threads::Threads) \ No newline at end of file diff --git a/executor/CMakeLists.txt b/executor/CMakeLists.txt index 53cd081..e8dc0a2 100644 --- a/executor/CMakeLists.txt +++ b/executor/CMakeLists.txt @@ -1,8 +1,11 @@ project(executor) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(executor_basic basic_usage.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(executor_basic PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(executor_basic ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(executor_basic Threads::Threads) \ No newline at end of file diff --git a/fixed-size-package/CMakeLists.txt b/fixed-size-package/CMakeLists.txt index ccb0730..817e93f 100644 --- a/fixed-size-package/CMakeLists.txt +++ b/fixed-size-package/CMakeLists.txt @@ -1,4 +1,7 @@ project(fixed-size-pkg) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(fixed-size-server server.cpp) add_executable(fixed-size-client client.cpp) @@ -6,7 +9,7 @@ add_executable(fixed-size-client client.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(fixed-size-server PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(fixed-size-server ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(fixed-size-server Threads::Threads) target_include_directories(fixed-size-client PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(fixed-size-client ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(fixed-size-client Threads::Threads) \ No newline at end of file diff --git a/httpclient-https/CMakeLists.txt b/httpclient-https/CMakeLists.txt index 7b4b936..767f66e 100644 --- a/httpclient-https/CMakeLists.txt +++ b/httpclient-https/CMakeLists.txt @@ -1,8 +1,11 @@ project(https_client) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) add_executable(${PROJECT_NAME} https-client.cpp AsyncHttpsClient.cpp) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ssl crypto) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} Threads::Threads ssl crypto) target_include_directories(${PROJECT_NAME} PUBLIC ${ASIO_INCLUDE_DIR} /usr/local/Cellar/openssl/1.0.2o_1/include) diff --git a/httpclient/CMakeLists.txt b/httpclient/CMakeLists.txt index c63c1e0..52a8c1b 100644 --- a/httpclient/CMakeLists.txt +++ b/httpclient/CMakeLists.txt @@ -1,8 +1,10 @@ project(http_client) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) add_executable(${PROJECT_NAME} http_client.cpp AsyncHttpClient.cpp) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} Threads::Threads) target_include_directories(${PROJECT_NAME} PUBLIC ${ASIO_INCLUDE_DIR}) - diff --git a/io_context/CMakeLists.txt b/io_context/CMakeLists.txt index 28e435e..9f32c04 100644 --- a/io_context/CMakeLists.txt +++ b/io_context/CMakeLists.txt @@ -1,8 +1,11 @@ project(io_context_usage) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(io_context_usage io_context_usage.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(io_context_usage PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(io_context_usage ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(io_context_usage Threads::Threads) \ No newline at end of file diff --git a/redis-asio/CMakeLists.txt b/redis-asio/CMakeLists.txt index c2111fa..7f5e5c5 100644 --- a/redis-asio/CMakeLists.txt +++ b/redis-asio/CMakeLists.txt @@ -1,4 +1,7 @@ project(redis-assio) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(mt-redis-cli multi-thread-client.cpp response_parser.cpp) add_executable(general-redis-cli general-client.cpp response_parser.cpp) @@ -7,10 +10,10 @@ add_executable(protocol_parser_test response_parser.cpp response_parser_test.cpp set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(mt-redis-cli PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(mt-redis-cli ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(mt-redis-cli Threads::Threads) target_include_directories(general-redis-cli PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(general-redis-cli ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(general-redis-cli Threads::Threads) target_include_directories(protocol_parser_test PRIVATE ${ASIO_INCLUDE_DIR} ${CATCH_SINGLE_INCLUDE}) -target_link_libraries(protocol_parser_test ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(protocol_parser_test Threads::Threads) \ No newline at end of file diff --git a/simplest_httpsvr/CMakeLists.txt b/simplest_httpsvr/CMakeLists.txt index 155dcb2..b17d1ee 100644 --- a/simplest_httpsvr/CMakeLists.txt +++ b/simplest_httpsvr/CMakeLists.txt @@ -1,6 +1,9 @@ project(simplest-httpsvr) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(simplest-httpsvr http_svr.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(simplest-httpsvr PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(simplest-httpsvr ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(simplest-httpsvr Threads::Threads) diff --git a/timer-performance/CMakeLists.txt b/timer-performance/CMakeLists.txt index 53252b3..659e616 100644 --- a/timer-performance/CMakeLists.txt +++ b/timer-performance/CMakeLists.txt @@ -1,8 +1,11 @@ project(timer_performance) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(tp main.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(tp PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(tp ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(tp Threads::Threads) \ No newline at end of file diff --git a/timer_usage/CMakeLists.txt b/timer_usage/CMakeLists.txt index 821ab68..8477951 100644 --- a/timer_usage/CMakeLists.txt +++ b/timer_usage/CMakeLists.txt @@ -1,4 +1,7 @@ project(timer_usage) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads REQUIRED) add_executable(timer_basic basic_usage.cpp) add_executable(timer_repeated repeated.cpp) @@ -6,7 +9,7 @@ add_executable(timer_repeated repeated.cpp) set(EXECUTABLE_OUTPUT_PATH ${BINARY_OUTPUT_DIR}) target_include_directories(timer_basic PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(timer_basic ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(timer_basic Threads::Threads) target_include_directories(timer_repeated PRIVATE ${ASIO_INCLUDE_DIR}) -target_link_libraries(timer_repeated ${CMAKE_THREAD_LIBS_INIT}) \ No newline at end of file +target_link_libraries(timer_repeated Threads::Threads)