From 0184f2e9f760a9ca4aff89838c8d0b9fe3171f11 Mon Sep 17 00:00:00 2001 From: Philip Hyunsu Cho Date: Tue, 14 Jan 2020 13:30:34 -0800 Subject: [PATCH] Explicitly use UTF-8 codepage when using MSVC (#5197) * Explicitly use UTF-8 codepage when using MSVC * Fix build with CUDA enabled --- src/CMakeLists.txt | 12 ++++++++++++ tests/cpp/CMakeLists.txt | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad11d892f..88b62088d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,12 @@ if (USE_CUDA) $<$:-Xcompiler=${OpenMP_CXX_FLAGS}> ) + if (MSVC) + target_compile_options(objxgboost PRIVATE + $<$:-Xcompiler=/utf-8> + ) + endif (MSVC) + set_target_properties(objxgboost PROPERTIES CUDA_SEPARABLE_COMPILATION OFF) else (USE_CUDA) @@ -52,6 +58,12 @@ if (WIN32 AND MINGW) target_compile_options(objxgboost PUBLIC -static-libstdc++) endif (WIN32 AND MINGW) +if (MSVC) + target_compile_options(objxgboost PRIVATE + $<$>:/utf-8> + ) +endif (MSVC) + set_target_properties(objxgboost PROPERTIES POSITION_INDEPENDENT_CODE ON CXX_STANDARD 11 diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index a4ddf33a7..f773aadc0 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -43,8 +43,19 @@ if (USE_CUDA) target_include_directories(testxgboost PRIVATE "${NVTX_HEADER_DIR}") target_compile_definitions(testxgboost PRIVATE -DXGBOOST_USE_NVTX=1) endif (USE_NVTX) + if (MSVC) + target_compile_options(testxgboost PRIVATE + $<$:-Xcompiler=/utf-8> + ) + endif (MSVC) endif (USE_CUDA) +if (MSVC) + target_compile_options(testxgboost PRIVATE + $<$>:/utf-8> + ) +endif (MSVC) + target_include_directories(testxgboost PRIVATE ${GTEST_INCLUDE_DIRS}