From 770090e901872f860c8c75b55b9df3253ab2de6f Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje <50274155+EduMenges@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:50:42 -0700 Subject: [PATCH] Removed specific MSVC settings when installing (#17285) When installing protobuf, it creates a different directory for CMake's config files when compiling with MSVC. ![protobuf-on-windows](https://github.com/protocolbuffers/protobuf/assets/50274155/b0f5e1fa-dcb8-4c01-8118-7c6c651cda37) _gRPC build on Windows_ ![protobuf-on-linux](https://github.com/protocolbuffers/protobuf/assets/50274155/1370b476-89e7-42a0-857d-73cdcbae4f23) _gRPC build on Linux and macOS_ This is problematic because it requires conditionally setting its `protobuf_DIR` for different platforms: ```cmake if(MSVC) set(Protobuf_DIR "${PROTOBUF_PREFIX}/cmake") else() set(Protobuf_DIR "${PROTOBUF_PREFIX}/lib/cmake/protobuf") endif() ``` [The original commit that made this](https://github.com/protocolbuffers/protobuf/commit/7d79458fc5d4392f68a08b9f9bef39fc8dcec861) based its choice on CMake's version 3.4, which not only is deprecated but is also based on a CMake version [less than the one defined in the master file](https://github.com/protocolbuffers/protobuf/blob/main/CMakeLists.txt#L3). Since then, CMake changed its behaviour, making this distinction unnecessary. Closes #17285 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/17285 from EduMenges:main a6f2e375cedd40c8a14378a190e319e8dc0e8682 PiperOrigin-RevId: 650455064 --- cmake/install.cmake | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 676d70236320..65765ca2903e 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -122,15 +122,9 @@ set(_install_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the c set(_build_cmakedir_desc "Directory relative to CMAKE_CURRENT_BINARY_DIR for cmake configuration files") set(_exampledir_desc "Directory relative to CMAKE_INSTALL_DATA to install examples") set(_protobuf_subdir_desc "Subdirectory in which to install cmake configuration files") -if(NOT MSVC) - set(protobuf_CMAKE_SUBDIR "cmake/protobuf" CACHE STRING "${_protobuf_subdir_desc}") - set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_install_cmakedir_desc}") - set(CMAKE_INSTALL_EXAMPLEDIR "${CMAKE_INSTALL_DATADIR}/protobuf/examples" CACHE STRING "${_exampledir_desc}") -else() - set(protobuf_CMAKE_SUBDIR "cmake" CACHE STRING "${_protobuf_subdir_desc}") - set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}") - set(CMAKE_INSTALL_EXAMPLEDIR "examples" CACHE STRING "${_exampledir_desc}") -endif() +set(protobuf_CMAKE_SUBDIR "cmake/protobuf" CACHE STRING "${_protobuf_subdir_desc}") +set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_install_cmakedir_desc}") +set(CMAKE_INSTALL_EXAMPLEDIR "${CMAKE_INSTALL_DATADIR}/protobuf/examples" CACHE STRING "${_exampledir_desc}") set(CMAKE_BUILD_CMAKEDIR "${CMAKE_CURRENT_BINARY_DIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_build_cmakedir_desc}") mark_as_advanced(protobuf_CMAKE_SUBDIR) mark_as_advanced(CMAKE_BUILD_CMAKEDIR)