Skip to content

Commit

Permalink
Separate DLL export/import for test helpers dll, and fix typo.
Browse files Browse the repository at this point in the history
The DLL export issue isn't a problem currently, since we don't explicitly export any symbols from the test dll.  This will be an issue in the future though.  Additionally, there was a typo in absl_internal_test_dll_contains that caused abseil_test_dll to be empty (and therefore not create a lib file).

PiperOrigin-RevId: 504555797
Change-Id: Ic7b50bcbe704f7c8fd44028071abcf5d6babb2cf
  • Loading branch information
mkruskal-google authored and Copybara-Service committed Jan 25, 2023
1 parent f1d1657 commit a69b0ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
20 changes: 12 additions & 8 deletions CMake/AbseilDll.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ function(absl_internal_test_dll_contains)
STRING(REGEX REPLACE "^absl::" "" _target ${ABSL_INTERNAL_TEST_DLL_TARGET})

list(FIND
ABSL_INTERNA_TEST_DLL_TARGETS
ABSL_INTERNAL_TEST_DLL_TARGETS
"${_target}"
_index)

Expand Down Expand Up @@ -703,14 +703,18 @@ function(absl_make_dll)
set(_dll "abseil_test_dll")
set(_dll_files ${ABSL_INTERNAL_TEST_DLL_FILES})
set(_dll_libs "abseil_dll" "GTest::gtest" "GTest::gmock")
set(_dll_compile_definiations "GTEST_LINKED_AS_SHARED_LIBRARY=1")
set(_dll_includes ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS})
set(_dll_compile_definitions "GTEST_LINKED_AS_SHARED_LIBRARY=1")
set(_dll_includes ${absl_gtest_src_dir}/googletest/include ${absl_gtest_src_dir}/googlemock/include)
set(_dll_consume "ABSL_CONSUME_TEST_DLL")
set(_dll_build "ABSL_BUILD_TEST_DLL")
else()
set(_dll "abseil_dll")
set(_dll_files ${ABSL_INTERNAL_DLL_FILES})
set(_dll_libs "")
set(_dll_compile_definiations "")
set(_dll_compile_definitions "")
set(_dll_includes "")
set(_dll_consume "ABSL_CONSUME_DLL")
set(_dll_build "ABSL_BUILD_DLL")
endif()

add_library(
Expand Down Expand Up @@ -762,21 +766,21 @@ Name: ${_dll}\n\
Description: Abseil DLL library\n\
URL: https://abseil.io/\n\
Version: ${absl_VERSION}\n\
Libs: -L\${libdir} ${PC_LINKOPTS} $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE}>>:-labseil_dll>\n\
Libs: -L\${libdir} ${PC_LINKOPTS} $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE}>>:-l${_dll}>\n\
Cflags: -I\${includedir}${PC_CFLAGS}\n")
INSTALL(FILES "${CMAKE_BINARY_DIR}/lib/pkgconfig/${_dll}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

target_compile_definitions(
${_dll}
PUBLIC
GTEST_LINKED_AS_SHARED_LIBRARY=1
${_dll_compile_definitions}
PRIVATE
ABSL_BUILD_DLL
${_dll_build}
NOMINMAX
INTERFACE
${ABSL_CC_LIB_DEFINES}
ABSL_CONSUME_DLL
${_dll_consume}
)

if(ABSL_PROPAGATE_CXX_STD)
Expand Down
3 changes: 2 additions & 1 deletion CMake/AbseilHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,15 @@ function(absl_cc_test)
target_sources(${_NAME} PRIVATE ${ABSL_CC_TEST_SRCS})
target_include_directories(${_NAME}
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}
PRIVATE ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
PRIVATE ${absl_gtest_src_dir}/googletest/include ${absl_gtest_src_dir}/googlemock/include
)

if (${ABSL_BUILD_DLL})
target_compile_definitions(${_NAME}
PUBLIC
${ABSL_CC_TEST_DEFINES}
ABSL_CONSUME_DLL
ABSL_CONSUME_TEST_DLL
GTEST_LINKED_AS_SHARED_LIBRARY=1
)

Expand Down
12 changes: 12 additions & 0 deletions absl/base/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,18 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#define ABSL_DLL
#endif // defined(_MSC_VER)

#if defined(_MSC_VER)
#if defined(ABSL_BUILD_TEST_DLL)
#define ABSL_TEST_DLL __declspec(dllexport)
#elif defined(ABSL_CONSUME_TEST_DLL)
#define ABSL_TEST_DLL __declspec(dllimport)
#else
#define ABSL_TEST_DLL
#endif
#else
#define ABSL_TEST_DLL
#endif // defined(_MSC_VER)

// ABSL_HAVE_MEMORY_SANITIZER
//
// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
Expand Down

0 comments on commit a69b0ae

Please sign in to comment.