Factor out MSVC-only `version.rc` logic, and ensure other variables are always initialized (#9880)

pull/9886/head
David L. Jones 3 years ago committed by GitHub
parent 4e5e8d325a
commit c4ddd84918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      CMakeLists.txt
  2. 8
      cmake/libprotobuf-lite.cmake
  3. 8
      cmake/libprotobuf.cmake
  4. 8
      cmake/libprotoc.cmake
  5. 8
      cmake/protoc.cmake
  6. 2
      cmake/tests.cmake

@ -289,23 +289,26 @@ if (MSVC)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_flags} <DEFINES> /fo<OBJECT> <SOURCE>") set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_flags} <DEFINES> /fo<OBJECT> <SOURCE>")
endif() endif()
# Generate the version.rc file used elsewhere.
configure_file(${protobuf_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) configure_file(${protobuf_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
endif (MSVC) set(protobuf_version_rc_file ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
include_directories(
${ZLIB_INCLUDE_DIRECTORIES}
${protobuf_BINARY_DIR}
${protobuf_SOURCE_DIR}/src)
if (MSVC)
# Add the "lib" prefix for generated .lib outputs. # Add the "lib" prefix for generated .lib outputs.
set(LIB_PREFIX lib) set(LIB_PREFIX lib)
else (MSVC) else (MSVC)
# No version.rc file.
set(protobuf_version_rc_file)
# When building with "make", "lib" prefix will be added automatically by # When building with "make", "lib" prefix will be added automatically by
# the build tool. # the build tool.
set(LIB_PREFIX) set(LIB_PREFIX)
endif (MSVC) endif (MSVC)
include_directories(
${ZLIB_INCLUDE_DIRECTORIES}
${protobuf_BINARY_DIR}
${protobuf_SOURCE_DIR}/src)
if (protobuf_UNICODE) if (protobuf_UNICODE)
add_definitions(-DUNICODE -D_UNICODE) add_definitions(-DUNICODE -D_UNICODE)
endif (protobuf_UNICODE) endif (protobuf_UNICODE)

@ -86,14 +86,8 @@ set(libprotobuf_lite_includes
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h
) )
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(libprotobuf_lite_rc_files
${CMAKE_CURRENT_BINARY_DIR}/version.rc
)
endif()
add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC} add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC}
${libprotobuf_lite_files} ${libprotobuf_lite_includes} ${libprotobuf_lite_rc_files}) ${libprotobuf_lite_files} ${libprotobuf_lite_includes} ${protobuf_version_rc_file})
if(protobuf_HAVE_LD_VERSION_SCRIPT) if(protobuf_HAVE_LD_VERSION_SCRIPT)
if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13) if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13)
target_link_options(libprotobuf-lite PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf-lite.map) target_link_options(libprotobuf-lite PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf-lite.map)

@ -99,14 +99,8 @@ set(libprotobuf_includes
${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.h
) )
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(libprotobuf_rc_files
${CMAKE_CURRENT_BINARY_DIR}/version.rc
)
endif()
add_library(libprotobuf ${protobuf_SHARED_OR_STATIC} add_library(libprotobuf ${protobuf_SHARED_OR_STATIC}
${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes} ${libprotobuf_rc_files}) ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes} ${protobuf_version_rc_file})
if(protobuf_HAVE_LD_VERSION_SCRIPT) if(protobuf_HAVE_LD_VERSION_SCRIPT)
if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13) if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13)
target_link_options(libprotobuf PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf.map) target_link_options(libprotobuf PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf.map)

@ -107,14 +107,8 @@ set(libprotoc_headers
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.h
) )
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(libprotoc_rc_files
${CMAKE_CURRENT_BINARY_DIR}/version.rc
)
endif()
add_library(libprotoc ${protobuf_SHARED_OR_STATIC} add_library(libprotoc ${protobuf_SHARED_OR_STATIC}
${libprotoc_files} ${libprotoc_headers} ${libprotoc_rc_files}) ${libprotoc_files} ${libprotoc_headers} ${protobuf_version_rc_file})
if(protobuf_HAVE_LD_VERSION_SCRIPT) if(protobuf_HAVE_LD_VERSION_SCRIPT)
if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13) if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13)
target_link_options(libprotoc PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotoc.map) target_link_options(libprotoc PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotoc.map)

@ -2,13 +2,7 @@ set(protoc_files
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/main.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/main.cc
) )
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_executable(protoc ${protoc_files} ${protobuf_version_rc_file})
set(protoc_rc_files
${CMAKE_CURRENT_BINARY_DIR}/version.rc
)
endif()
add_executable(protoc ${protoc_files} ${protoc_rc_files})
target_link_libraries(protoc target_link_libraries(protoc
libprotoc libprotoc
libprotobuf libprotobuf

@ -245,6 +245,8 @@ if(protobuf_TEST_XML_OUTDIR)
string(APPEND protobuf_TEST_XML_OUTDIR "/") string(APPEND protobuf_TEST_XML_OUTDIR "/")
endif() endif()
set(protobuf_GTEST_ARGS "--gtest_output=xml:${protobuf_TEST_XML_OUTDIR}") set(protobuf_GTEST_ARGS "--gtest_output=xml:${protobuf_TEST_XML_OUTDIR}")
else()
set(protobuf_GTEST_ARGS)
endif() endif()
add_executable(tests ${tests_files}) add_executable(tests ${tests_files})

Loading…
Cancel
Save