Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mangle the path in the test target. Glob for test files.
  • Loading branch information
vgvassilev committed Apr 6, 2017
commit 4198148861a094c48862d1b5e3709cfa7364c36a
53 changes: 40 additions & 13 deletions cmake/modules/RootNewMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,43 @@ function(ROOT_ADD_TEST test)

endfunction()

#----------------------------------------------------------------------------
# ROOT_PATH_TO_STRING( <variable> path PATH_SEPARATOR_REPLACEMENT replacement )
#
# Mangle the path to a string.
#----------------------------------------------------------------------------
function(ROOT_PATH_TO_STRING resultvar path)
# FIXME: Copied and modified from ROOTTEST_TARGETNAME_FROM_FILE. We should find a common place for that code.
# FIXME: ROOTTEST_TARGETNAME_FROM_FILE could be replaced by just a call to string(MAKE_C_IDENTIFIER)...
CMAKE_PARSE_ARGUMENTS(ARG "" "" "PATH_SEPARATOR_REPLACEMENT" ${ARGN})

set(sep_replacement "")
if (ARG_PATH_SEPARATOR_REPLACEMENT)
set(sep_replacement ${ARG_PATH_SEPARATOR_REPLACEMENT})
endif()

get_filename_component(realfp ${path} ABSOLUTE)
get_filename_component(filename_we ${path} NAME_WE)

string(REPLACE "${CMAKE_SOURCE_DIR}" "" relativepath ${realfp})
string(REPLACE "${path}" "" relativepath ${relativepath})

string(MAKE_C_IDENTIFIER ${relativepath}${filename_we} mangledname)
string(REPLACE "_" "${sep_replacement}" mangledname ${mangledname})

set(${resultvar} "${mangledname}" PARENT_SCOPE)
endfunction(ROOT_PATH_TO_STRING)

#----------------------------------------------------------------------------
# ROOT_ADD_UNITTEST_SUBDIRECTORY( <name> LIBRARIES)
#----------------------------------------------------------------------------
function(ROOT_ADD_UNITTEST_SUBDIRECTORY subdir)
ROOT_GLOB_FILES(test_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/*.cxx)
# Get the component from the path. Eg. core to form coreTests test suite name.
ROOT_PATH_TO_STRING(test_name ${CMAKE_CURRENT_SOURCE_DIR}/Tests/)
ROOT_ADD_GTEST(${test_name} ${test_files} ${ARGN})
endfunction()

#----------------------------------------------------------------------------
# function ROOT_ADD_GTEST(<testsuite> source1 source2... LIBRARIES)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that LIBRARIES <lib1> <lib2> or how does that work? Could you clarify in the comment/doc?

#
Expand All @@ -1091,21 +1128,11 @@ function(ROOT_ADD_GTEST test_suite)
# FIXME: For better coherence we could restrict the libraries the test suite could link
# against. For example, tests in Core should link only against libCore. This could be tricky
# to implement because some ROOT components create more than one library.
ROOT_EXECUTABLE(${test_suite} ${source_files} LIBRARIES ${ARG_LIBRARIES})
ROOT_EXECUTABLE(${test_suite} NOINSTALL ${source_files} LIBRARIES ${ARG_LIBRARIES})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peremato, this is the problematic line that puts the test binary in the ROOT install dir.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default output directory for binaries is controlled by this variable CMAKE_RUNTIME_OUTPUT_DIRECTORY. On possibility is to clear the variable before calling ROOT_EXECUTABLE(...) or setting the specific target property afterwards with

set_property(TARGET ${test_suite} 
                       PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(${test_suite} gtest gtest_main gmock gmock_main)

# Mangle the path to the test name.
# FIXME: Copied and modified from ROOTTEST_TARGETNAME_FROM_FILE. We should find a common place for that code.
set(filename ${test_suite})
get_filename_component(realfp ${filename} ABSOLUTE)
get_filename_component(filename_we ${filename} NAME_WE)

string(REPLACE "${CMAKE_SOURCE_DIR}" "" relativepath ${realfp})
string(REPLACE "${filename}" "" relativepath ${relativepath})

string(REPLACE "/" "-" targetname ${relativepath}${filename_we})

ROOT_ADD_TEST(gtest${targetname} COMMAND ${test_suite})
ROOT_PATH_TO_STRING(mangled_name ${test_suite} PATH_SEPARATOR_REPLACEMENT "-")
ROOT_ADD_TEST(gtest${mangled_name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test_suite})
endfunction()


Expand Down
5 changes: 4 additions & 1 deletion core/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
############################################################################

if(testing)
ROOT_ADD_TEST_SUBDIRECTORY(test)
# FIXME: The tests in core should require only libCore. OTOH, TQObjectTests uses the interpreter to register the class.
# This means that if we run make CoreBaseTests the executable wouldn't be runnable because it requires libCling and
# onepcm targets to be built.
ROOT_ADD_UNITTEST_SUBDIRECTORY(test LIBRARIES Core Cling RIO)
endif()

ROOT_GLOB_HEADERS(Base_dict_headers ${CMAKE_CURRENT_SOURCE_DIR}/inc/T*.h
Expand Down
10 changes: 0 additions & 10 deletions core/base/test/CMakeLists.txt

This file was deleted.