Loosen requirements for static c-ares library when building tests

It appears that when building tests, it would hardcode enabling building
of the c-ares static library.  This was probably due to Windows limitations
in symbol visibility.

This change will use the static library if it exists for tests, always.
Otherwise, it will only forcibly enable static libraries for tests on
Windows.

Fixes: #380
Fix By: Brad House (@bradh352)
pull/386/head
bradh352 4 years ago
parent 7d033ebabd
commit bdeb386a84
  1. 5
      CMakeLists.txt
  2. 6
      test/CMakeLists.txt

@ -37,10 +37,11 @@ OPTION (CARES_BUILD_TESTS "Build and run tests"
OPTION (CARES_BUILD_CONTAINER_TESTS "Build and run container tests (implies CARES_BUILD_TESTS, Linux only)" OFF)
OPTION (CARES_BUILD_TOOLS "Build tools" ON)
# Tests require static to be enabled
IF (CARES_BUILD_TESTS)
# Tests require static to be enabled on Windows to be able to access otherwise hidden symbols
IF (CARES_BUILD_TESTS AND (NOT CARES_STATIC) AND WIN32)
SET (CARES_STATIC ON)
SET (CARES_STATIC_PIC ON)
MESSAGE (WARNING "Static building was requested be disabled, but reenabled to support tests")
ENDIF ()
# allow linking against the static runtime library in msvc

@ -18,7 +18,11 @@ target_include_directories(caresinternal
"${CMAKE_INSTALL_INCLUDEDIR}"
)
target_link_libraries(caresinternal INTERFACE ${PROJECT_NAME}::cares_static)
IF (CARES_STATIC)
target_link_libraries(caresinternal INTERFACE ${PROJECT_NAME}::cares_static)
ELSE ()
target_link_libraries(caresinternal INTERFACE ${PROJECT_NAME}::cares)
ENDIF ()
# Google Test and Mock
set(GMOCK_DIR gmock-1.8.0)

Loading…
Cancel
Save