Fix double linkage for tests
authorRoland Schulz <roland@utk.edu>
Tue, 16 Sep 2014 00:08:19 +0000 (20:08 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Thu, 18 Sep 2014 08:03:41 +0000 (10:03 +0200)
cmake automatically adds libraries required by a required library to the
exe linker flags. If the same dependent library is also added for the exe
and it is listed first for the exe, cmake links twice for static libs
(for a cyclic dependency it would be required and cmake can't know).
Under certain conditions (e.g. ICC 15 with static libraries and offload
enabled) this can cause linker errors. We don't have a cyclic dependency
and thus by listing libgromacs after testutils we avoid the potential
problematic double linking. Also fixes that TESTUTILS_LIBS contains
the transitive dependencies, because that is not necessary (they are anyhow
added automatically).

Change-Id: I0327b2dba0538a2c6652c484fd7be7ae4a6cfb5b

src/testutils/CMakeLists.txt
src/testutils/TestMacros.cmake

index 1941dbcb2f70743d4af3ec23dc85fc4fc4378f6d..6366b970843dfe82a77ac20ddec3b8aa2bc63e2d 100644 (file)
@@ -37,7 +37,7 @@ include_directories(${LIBXML2_INCLUDE_DIR})
 file(GLOB TESTUTILS_SOURCES *.cpp)
 
 add_library(testutils STATIC ${UNITTEST_TARGET_OPTIONS} ${TESTUTILS_SOURCES})
-set(TESTUTILS_LIBS testutils ${GMOCK_LIBRARIES} ${LIBXML2_LIBRARIES})
+set(TESTUTILS_LIBS testutils)
 set_property(TARGET testutils APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}")
 target_link_libraries(testutils libgromacs ${GMOCK_LIBRARIES} ${LIBXML2_LIBRARIES})
 
index 0796c6993c87df2f64fd22e8ac84ab674a34ce88..b3acdbefd16539468521696d034ef14e18d7900b 100644 (file)
@@ -45,7 +45,7 @@ function (gmx_build_unit_test NAME EXENAME)
         include_directories(BEFORE ${GMOCK_INCLUDE_DIRS})
         add_executable(${EXENAME} ${UNITTEST_TARGET_OPTIONS} ${ARGN} ${TESTUTILS_DIR}/unittest_main.cpp)
         set_property(TARGET ${EXENAME} APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}")
-        target_link_libraries(${EXENAME} libgromacs ${TESTUTILS_LIBS} ${GMOCK_LIBRARIES} ${GMX_EXE_LINKER_FLAGS})
+        target_link_libraries(${EXENAME} ${TESTUTILS_LIBS} libgromacs ${GMOCK_LIBRARIES} ${GMX_EXE_LINKER_FLAGS})
         set(_temporary_files_path "${CMAKE_CURRENT_BINARY_DIR}/Testing/Temporary")
         file(MAKE_DIRECTORY ${_temporary_files_path})