Skip to content

Commit

Permalink
fix msvc compile failed (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust authored and ywy2090 committed Apr 10, 2023
1 parent 9742d80 commit 007a4be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})

# install dependencies
hunter_add_package(Boost COMPONENTS all)
if(NOT MSVC)
hunter_add_package(range-v3)
find_package(range-v3 CONFIG REQUIRED)
endif()
# for compile
set(BCOS_UTILITIES_TARGET "bcos-utilities")
add_subdirectory(bcos-utilities)

if (TESTS)
if (TESTS)
enable_testing()
set(CTEST_OUTPUT_ON_FAILURE TRUE)
add_subdirectory(tests)
Expand Down
17 changes: 13 additions & 4 deletions bcos-cmake-scripts/CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
endif()
endif ()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")

# Only support visual studio 2017 and visual studio 2019
set(MSVC_MIN_VERSION "1914") # VS2017 15.7, for full-ish C++17 support
set(MSVC_MIN_VERSION "1914") # VS2017 15.7, for full-ish C++20 support

message(STATUS "Compile On Windows, MSVC_TOOLSET_VERSION: ${MSVC_TOOLSET_VERSION}")

if (MSVC_TOOLSET_VERSION EQUAL 141)
Expand All @@ -152,7 +152,16 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
message(FATAL_ERROR "Unsupported Visual Studio, supported list: [2017, 2019]. Current MSVC_TOOLSET_VERSION: ${MSVC_TOOLSET_VERSION}")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
add_definitions(-DUSE_STD_RANGES)
add_compile_options(/std:c++latest)
add_compile_options(-bigobj)

# MSVC only support static build
set(CMAKE_CXX_FLAGS_DEBUG "/MTd /DEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /Os")
set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /DEBUG")
link_libraries(ws2_32 Crypt32 userenv)
else ()
message(WARNING "Your compiler is not tested, if you run into any issues, we'd welcome any patches.")
endif ()
Expand Down

0 comments on commit 007a4be

Please sign in to comment.