Skip to content

Commit

Permalink
Improve test building with the Xcode generator.
Browse files Browse the repository at this point in the history
Add CONFIGURATIONS keyword to unadorned tests, enables tests with
multi-config generators.
Add CONFIGURATION generator expression to libgtest.a and libgmock.a
build directory specs when building with Xcode so that it can
find them when building tests.
  • Loading branch information
jralls committed Mar 24, 2020
1 parent 8fc901f commit 33902a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions common/cmake_modules/GncAddTest.cmake
Expand Up @@ -78,7 +78,7 @@ function(gnc_add_test _TARGET _SOURCE_FILES TEST_INCLUDE_VAR_NAME TEST_LIBS_VAR_
)
set_tests_properties(${_TARGET} PROPERTIES ENVIRONMENT "GNC_UNINSTALLED=YES;GNC_BUILDDIR=${CMAKE_BINARY_DIR};${ARGN}")
else()
add_test(NAME ${_TARGET} COMMAND ${_TARGET})
add_test(NAME ${_TARGET} COMMAND ${_TARGET} CONFIGURATIONS Debug;Release)
set_tests_properties(${_TARGET} PROPERTIES ENVIRONMENT "GNC_UNINSTALLED=YES;GNC_BUILDDIR=${CMAKE_BINARY_DIR}")
endif()
add_dependencies(check ${_TARGET})
Expand Down Expand Up @@ -133,7 +133,11 @@ function(gnc_gtest_configure)
"${GTEST_SRC_DIR}/src/gtest_main.cc"
"${GTEST_SRC_DIR}/src/gtest-all.cc"
PARENT_SCOPE)
set(GTEST_LIB "${CMAKE_BINARY_DIR}/common/test-core/libgtest.a" PARENT_SCOPE)
if (CMAKE_GENERATOR STREQUAL Xcode)
set(GTEST_LIB "${CMAKE_BINARY_DIR}/common/test-core/$<CONFIGURATION>/libgtest.a" PARENT_SCOPE)
else()
set(GTEST_LIB "${CMAKE_BINARY_DIR}/common/test-core/libgtest.a" PARENT_SCOPE)
endif()
endif()
else()
message(FATAL_ERROR "GTEST not found. Please install it or set GTEST_ROOT or GMOCK_ROOT")
Expand Down Expand Up @@ -163,7 +167,11 @@ function(gnc_gtest_configure)
unset(GMOCK_SRC_DIR CACHE)
else()
set(GMOCK_SRC "${GMOCK_MAIN_SRC_DIR}/gmock-all.cc" PARENT_SCOPE)
set(GMOCK_LIB "${CMAKE_BINARY_DIR}/common/test-core/libgmock.a" PARENT_SCOPE)
if (CMAKE_GENERATOR STREQUAL Xcode)
set(GMOCK_LIB "${CMAKE_BINARY_DIR}/common/test-core/$<CONFIGURATION>/libgmock.a" PARENT_SCOPE)
else()
set(GMOCK_LIB "${CMAKE_BINARY_DIR}/common/test-core/libgmock.a" PARENT_SCOPE)
endif()
endif()
else()
message(FATAL_ERROR "GMOCK not found. Please install it or set GMOCK_ROOT")
Expand Down
1 change: 1 addition & 0 deletions libgnucash/backend/xml/test/CMakeLists.txt
Expand Up @@ -98,5 +98,6 @@ set(test-real-data-env
add_test(NAME test-real-data
COMMAND ${CMAKE_COMMAND} -E env
${SHELL} ${CMAKE_CURRENT_SOURCE_DIR}/test-real-data.sh
CONFIGURATIONS Debug;Release
)
set_tests_properties(test-real-data PROPERTIES ENVIRONMENT "${test-real-data-env}")
2 changes: 1 addition & 1 deletion libgnucash/engine/test/CMakeLists.txt
Expand Up @@ -19,7 +19,7 @@ endmacro()

add_executable(test-link EXCLUDE_FROM_ALL test-link.c)
target_link_libraries(test-link gnc-core-utils)
add_test(NAME test-link COMMAND test-link)
add_test(NAME test-link COMMAND test-link CONFIGURATIONS Debug;Release)
add_dependencies(check test-link)

#################################################
Expand Down

0 comments on commit 33902a6

Please sign in to comment.