Skip to content

Commit

Permalink
Kill /NODEFAULTLIB warnings when compiling tests under MSVC in debug
Browse files Browse the repository at this point in the history
They were caused by gtest/gmock statically linking to the release
runtime in debug mode.
The fix has required patching gmock/CMakeLists & gtest/CMakeLists to remove
hard-coded /MD switch. This patch has already been incorporated in to
gmock 1.7.0 but we cannot upgrade since this does not compile with the
std=c++0x flag on gcc.
Refs #8408
  • Loading branch information
martyngigg committed Nov 13, 2013
1 parent 6f3b667 commit 92a54f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
14 changes: 11 additions & 3 deletions Code/Mantid/TestingTools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#add_subdirectory( gtest-1.6.0 )
if( MSVC )
# We are building static libraries but we want them to dynamically link
# the to C/C++ runtime or we get duplicate library warnings
set ( gtest_force_shared_crt ON )
endif()
add_subdirectory( gmock-1.6.0 )

set_target_properties( gmock PROPERTIES EXCLUDE_FROM_ALL TRUE )
set_target_properties( gtest PROPERTIES EXCLUDE_FROM_ALL TRUE )
# Put the targets in the UnitTests folder
foreach( target_var
gmock gtest )
set_target_properties( ${target_var} PROPERTIES EXCLUDE_FROM_ALL TRUE
FOLDER "UnitTests/gmock" )
endforeach()
7 changes: 4 additions & 3 deletions Code/Mantid/TestingTools/gmock-1.6.0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ include_directories("${gmock_SOURCE_DIR}/include"
# are used for other targets, to ensure that Google Mock can be compiled by
# a user aggressive about warnings.

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set ( cxx_strict "/MD ${cxx_strict}")
endif()
## MANTID: Not required, this is done by cmake & has been removed in gmock-1.7.0 ##
# if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# set ( cxx_strict "/MD ${cxx_strict}")
#endif()

cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
target_link_libraries(gmock gtest)
Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/TestingTools/gmock-1.6.0/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ link_directories(${gtest_BINARY_DIR}/src)
# Google Test libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that gtest can be compiled by a user
# aggressive about warnings.
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set ( cxx_strict "/MD ${cxx_strict}")
endif()
## MANTID: Not required, this is done by cmake & has been removed in gmock-1.7.0 ##
#if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# set ( cxx_strict "/MD ${cxx_strict}")
#endif()
cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
#cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
#target_link_libraries(gtest_main gtest)
Expand Down

0 comments on commit 92a54f5

Please sign in to comment.