Repository navigation
ARROW-5403: [C++] Use GTest shared libraries with BUNDLED build, always use BUNDLED with MSVC #4380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c83c7d6
ac73ae3
c88d125
8678632
515f75b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,14 @@ set(ARROW_THIRDPARTY_DEPENDENCIES | |
| ZLIB | ||
| ZSTD) | ||
|
|
||
| # TODO(wesm): External GTest shared libraries are not currently | ||
| # supported when building with MSVC because of the way that | ||
| # conda-forge packages have 4 variants of the libraries packaged | ||
| # together | ||
| if(MSVC AND "${GTest_SOURCE}" STREQUAL "") | ||
| set(GTest_SOURCE "BUNDLED") | ||
| endif() | ||
|
|
||
| message(STATUS "Using ${ARROW_DEPENDENCY_SOURCE} approach to find dependencies") | ||
|
|
||
| # TODO: double-conversion check fails for conda, it should not | ||
|
|
@@ -1183,51 +1191,82 @@ macro(build_gtest) | |
| -Wno-unused-value -Wno-ignored-attributes) | ||
| endif() | ||
|
|
||
| if(MSVC) | ||
| set(GTEST_CMAKE_CXX_FLAGS "${GTEST_CMAKE_CXX_FLAGS} -DGTEST_CREATE_SHARED_LIBRARY=1") | ||
| endif() | ||
|
|
||
| set(GTEST_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/googletest_ep-prefix/src/googletest_ep") | ||
| set(GTEST_INCLUDE_DIR "${GTEST_PREFIX}/include") | ||
|
|
||
| if(MSVC) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kou can you confirm if this is needed with MinGW also (so WIN32 instead of MSVC)?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've confirmed. This isn't needed with MinGW. |
||
| set(_GTEST_IMPORTED_TYPE IMPORTED_IMPLIB) | ||
| set(_GTEST_LIBRARY_SUFFIX | ||
| "${CMAKE_GTEST_DEBUG_EXTENSION}${CMAKE_IMPORT_LIBRARY_SUFFIX}") | ||
| else() | ||
| set(_GTEST_IMPORTED_TYPE IMPORTED_LOCATION) | ||
| set(_GTEST_LIBRARY_SUFFIX | ||
| "${CMAKE_GTEST_DEBUG_EXTENSION}${CMAKE_SHARED_LIBRARY_SUFFIX}") | ||
| endif() | ||
|
|
||
| set(GTEST_SHARED_LIB | ||
| "${GTEST_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}gtest${_GTEST_LIBRARY_SUFFIX}") | ||
| set(GMOCK_SHARED_LIB | ||
| "${GTEST_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}gmock${_GTEST_LIBRARY_SUFFIX}") | ||
| set( | ||
| GTEST_STATIC_LIB | ||
| "${GTEST_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_GTEST_DEBUG_EXTENSION}${CMAKE_STATIC_LIBRARY_SUFFIX}" | ||
| ) | ||
| set( | ||
| GTEST_MAIN_STATIC_LIB | ||
| "${GTEST_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_GTEST_DEBUG_EXTENSION}${CMAKE_STATIC_LIBRARY_SUFFIX}" | ||
| GTEST_MAIN_SHARED_LIB | ||
|
|
||
| "${GTEST_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}gtest_main${_GTEST_LIBRARY_SUFFIX}" | ||
| ) | ||
| set(GTEST_CMAKE_ARGS ${EP_COMMON_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=${GTEST_PREFIX}" | ||
| "-DCMAKE_INSTALL_LIBDIR=lib" | ||
| -DCMAKE_CXX_FLAGS=${GTEST_CMAKE_CXX_FLAGS}) | ||
| set(GTEST_CMAKE_ARGS | ||
| ${EP_COMMON_TOOLCHAIN} | ||
| -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
| "-DCMAKE_INSTALL_PREFIX=${GTEST_PREFIX}" | ||
| "-DCMAKE_INSTALL_LIBDIR=lib" | ||
| -DBUILD_SHARED_LIBS=ON | ||
| -DCMAKE_CXX_FLAGS=${GTEST_CMAKE_CXX_FLAGS} | ||
| -DCMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}=${GTEST_CMAKE_CXX_FLAGS}) | ||
| set(GMOCK_INCLUDE_DIR "${GTEST_PREFIX}/include") | ||
| set( | ||
| GMOCK_STATIC_LIB | ||
| "${GTEST_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_GTEST_DEBUG_EXTENSION}${CMAKE_STATIC_LIBRARY_SUFFIX}" | ||
| ) | ||
|
|
||
| if(MSVC) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The googletest DLLs have to be put in the same directory as the build artifacts otherwise they won't be found when you run |
||
| if("${CMAKE_GENERATOR}" STREQUAL "Ninja") | ||
| set(_GTEST_LIBRARY_DIR ${BUILD_OUTPUT_ROOT_DIRECTORY}) | ||
| else() | ||
| set(_GTEST_LIBRARY_DIR ${BUILD_OUTPUT_ROOT_DIRECTORY}/${CMAKE_BUILD_TYPE}) | ||
| endif() | ||
|
|
||
| set(GTEST_CMAKE_ARGS | ||
| ${GTEST_CMAKE_ARGS} "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${_GTEST_LIBRARY_DIR}" | ||
| "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE}=${_GTEST_LIBRARY_DIR}") | ||
| endif() | ||
|
|
||
| add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1) | ||
|
|
||
| if(MSVC AND NOT ARROW_USE_STATIC_CRT) | ||
| set(GTEST_CMAKE_ARGS ${GTEST_CMAKE_ARGS} -Dgtest_force_shared_crt=ON) | ||
| endif() | ||
|
|
||
| externalproject_add(googletest_ep | ||
| URL ${GTEST_SOURCE_URL} | ||
| BUILD_BYPRODUCTS ${GTEST_STATIC_LIB} ${GTEST_MAIN_STATIC_LIB} | ||
| ${GMOCK_STATIC_LIB} | ||
| BUILD_BYPRODUCTS ${GTEST_SHARED_LIB} ${GTEST_MAIN_SHARED_LIB} | ||
| ${GMOCK_SHARED_LIB} | ||
| CMAKE_ARGS ${GTEST_CMAKE_ARGS} ${EP_LOG_OPTIONS}) | ||
|
|
||
| # The include directory must exist before it is referenced by a target. | ||
| file(MAKE_DIRECTORY "${GTEST_INCLUDE_DIR}") | ||
|
|
||
| add_library(GTest::GTest STATIC IMPORTED) | ||
| add_library(GTest::GTest SHARED IMPORTED) | ||
| set_target_properties(GTest::GTest | ||
| PROPERTIES IMPORTED_LOCATION "${GTEST_STATIC_LIB}" | ||
| PROPERTIES ${_GTEST_IMPORTED_TYPE} "${GTEST_SHARED_LIB}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}") | ||
|
|
||
| add_library(GTest::Main STATIC IMPORTED) | ||
| add_library(GTest::Main SHARED IMPORTED) | ||
| set_target_properties(GTest::Main | ||
| PROPERTIES IMPORTED_LOCATION "${GTEST_MAIN_STATIC_LIB}" | ||
| PROPERTIES ${_GTEST_IMPORTED_TYPE} "${GTEST_MAIN_SHARED_LIB}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}") | ||
|
|
||
| add_library(GTest::GMock STATIC IMPORTED) | ||
| add_library(GTest::GMock SHARED IMPORTED) | ||
| set_target_properties(GTest::GMock | ||
| PROPERTIES IMPORTED_LOCATION "${GMOCK_STATIC_LIB}" | ||
| PROPERTIES ${_GTEST_IMPORTED_TYPE} "${GMOCK_SHARED_LIB}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}") | ||
| add_dependencies(toolchain-tests googletest_ep) | ||
| add_dependencies(GTest::GTest googletest_ep) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we force that only if the user didn't pass
GTest_SOURCEexplicitly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed