From 96e56c367645759546e3f985dfba162de7dc940b Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 10 Dec 2022 07:09:48 +0000 Subject: [PATCH 1/3] make tree minimally compatible with VS2022 --- CMakeLists.txt | 2 +- depends/protobuf/CMakeLists.txt | 11 ++++++----- depends/protobuf/google/protobuf/stubs/hash.h | 13 ++++++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e657912..635bf383e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ if(UNIX) endif() if(WIN32) - if((NOT MSVC) OR (MSVC_VERSION LESS 1900) OR (MSVC_VERSION GREATER 1919)) + if((NOT MSVC) OR (MSVC_VERSION LESS 1930) OR (MSVC_VERSION GREATER 1934)) message(SEND_ERROR "MSVC 2015 or 2017 is required") endif() endif() diff --git a/depends/protobuf/CMakeLists.txt b/depends/protobuf/CMakeLists.txt index b12230b71..1d1796d1c 100644 --- a/depends/protobuf/CMakeLists.txt +++ b/depends/protobuf/CMakeLists.txt @@ -149,7 +149,7 @@ if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result -Wno-unused-local-typedefs -Wno-misleading-indentation -Wno-class-memaccess -Wno-sign-compare") elseif(MSVC) # Disable warnings for integer conversion to smaller type - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4273") endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -159,15 +159,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) # Protobuf shared libraries -add_library(protobuf SHARED ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS}) -ide_folder(protobuf "Depends") add_library(protobuf-lite SHARED ${LIBPROTOBUF_LITE_SRCS} ${LIBPROTOBUF_LITE_HDRS}) ide_folder(protobuf-lite "Depends") -set_target_properties(protobuf PROPERTIES COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS) set_target_properties(protobuf-lite PROPERTIES COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS) -target_link_libraries(protobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) target_link_libraries(protobuf-lite ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) install(TARGETS protobuf-lite @@ -175,6 +171,11 @@ install(TARGETS protobuf-lite RUNTIME DESTINATION ${DFHACK_LIBRARY_DESTINATION}) if(NOT CMAKE_CROSSCOMPILING) + add_library(protobuf SHARED ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS}) + ide_folder(protobuf "Depends") + set_target_properties(protobuf PROPERTIES COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS) + target_link_libraries(protobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) + # Protobuf compiler shared library add_library(protoc SHARED ${LIBPROTOC_SRCS} ${LIBPROTOC_HDRS}) diff --git a/depends/protobuf/google/protobuf/stubs/hash.h b/depends/protobuf/google/protobuf/stubs/hash.h index b4b2da574..0ee778563 100644 --- a/depends/protobuf/google/protobuf/stubs/hash.h +++ b/depends/protobuf/google/protobuf/stubs/hash.h @@ -104,7 +104,14 @@ // And.. they are moved back to stdext in MSVC 2013 (haven't checked 2012). That // said, use unordered_map for MSVC 2010 and beyond is our safest bet. #elif defined(_MSC_VER) -# if _MSC_VER >= 1600 // Since Visual Studio 2010 +# if _MSC_VER >= 1900 // Since Visual Studio 2019 +# define GOOGLE_PROTOBUF_HASH_NAMESPACE std +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set + +# elif _MSC_VER >= 1600 // Since Visual Studio 2010 # define GOOGLE_PROTOBUF_HAS_CXX11_HASH # define GOOGLE_PROTOBUF_HASH_COMPARE std::hash_compare # elif _MSC_VER >= 1500 // Since Visual Studio 2008 @@ -233,7 +240,7 @@ namespace google { HashFcn hash_function() const { return HashFcn(); } }; -#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) +#elif defined(_MSC_VER) && _MSC_VER < 1900 && !defined(_STLPORT_VERSION) template struct hash : public GOOGLE_PROTOBUF_HASH_COMPARE { @@ -435,4 +442,4 @@ namespace google { } // namespace protobuf } // namespace google -#endif // GOOGLE_PROTOBUF_STUBS_HASH_H__ \ No newline at end of file +#endif // GOOGLE_PROTOBUF_STUBS_HASH_H__ From e5f0668afd0ef346019670932fcff9c4159bb409 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 10 Dec 2022 18:11:32 -0800 Subject: [PATCH 2/3] fix error message for VS version requirement --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 635bf383e..b40b4e441 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ endif() if(WIN32) if((NOT MSVC) OR (MSVC_VERSION LESS 1930) OR (MSVC_VERSION GREATER 1934)) - message(SEND_ERROR "MSVC 2015 or 2017 is required") + message(SEND_ERROR "MSVC 2022 is required") endif() endif() From 2ef36b9cccd45373549c17006e288fc35445e9be Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 10 Dec 2022 18:13:19 -0800 Subject: [PATCH 3/3] clarify logic for selecting 32 vs 64 bit --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b40b4e441..783cb7b20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,10 +102,10 @@ endif() # Automatically detect architecture based on Visual Studio generator if(MSVC AND NOT DEFINED DFHACK_BUILD_ARCH) - if(${CMAKE_GENERATOR} MATCHES "Win64") - set(DFHACK_BUILD_ARCH "64") - else() + if ((${CMAKE_GENERATOR} MATCHES "Win32") OR (${CMAKE_GENERATOR} MATCHES "x86")) set(DFHACK_BUILD_ARCH "32") + else() + set(DFHACK_BUILD_ARCH "64") endif() else() set(DFHACK_BUILD_ARCH "64" CACHE STRING "Architecture to build ('32' or '64')")