diff --git a/CMakeLists.txt b/CMakeLists.txt index 7693c3c0e2..dd8977843a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,23 +289,26 @@ if (MSVC) set(CMAKE_RC_COMPILE_OBJECT " ${rc_flags} /fo ") endif() + # Generate the version.rc file used elsewhere. 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. set(LIB_PREFIX lib) else (MSVC) + # No version.rc file. + set(protobuf_version_rc_file) + # When building with "make", "lib" prefix will be added automatically by # the build tool. set(LIB_PREFIX) endif (MSVC) +include_directories( + ${ZLIB_INCLUDE_DIRECTORIES} + ${protobuf_BINARY_DIR} + ${protobuf_SOURCE_DIR}/src) + if (protobuf_UNICODE) add_definitions(-DUNICODE -D_UNICODE) endif (protobuf_UNICODE) diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index 0f3295569b..04a4ba0220 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -86,14 +86,8 @@ set(libprotobuf_lite_includes ${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} - ${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(${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) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 49f31c507c..9f3bdb22fc 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -99,14 +99,8 @@ set(libprotobuf_includes ${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} - ${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(${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) diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 625d65d545..0ece6593ac 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -107,14 +107,8 @@ set(libprotoc_headers ${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} - ${libprotoc_files} ${libprotoc_headers} ${libprotoc_rc_files}) + ${libprotoc_files} ${libprotoc_headers} ${protobuf_version_rc_file}) if(protobuf_HAVE_LD_VERSION_SCRIPT) 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) diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake index 7d04196b45..385a7a3f39 100644 --- a/cmake/protoc.cmake +++ b/cmake/protoc.cmake @@ -2,13 +2,7 @@ set(protoc_files ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/main.cc ) -if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") -set(protoc_rc_files - ${CMAKE_CURRENT_BINARY_DIR}/version.rc -) -endif() - -add_executable(protoc ${protoc_files} ${protoc_rc_files}) +add_executable(protoc ${protoc_files} ${protobuf_version_rc_file}) target_link_libraries(protoc libprotoc libprotobuf diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 789ae4f1c3..1f8bbc9d43 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -245,6 +245,8 @@ if(protobuf_TEST_XML_OUTDIR) string(APPEND protobuf_TEST_XML_OUTDIR "/") endif() set(protobuf_GTEST_ARGS "--gtest_output=xml:${protobuf_TEST_XML_OUTDIR}") +else() + set(protobuf_GTEST_ARGS) endif() add_executable(tests ${tests_files})