Skip to content

Commit

Permalink
Allow cet_script targets as TEST_EXEC without PATH
Browse files Browse the repository at this point in the history
A corner case of cet_test usage is when passing cet_script s, e.g.

cet_script(foo)
...
cet_test(bar HANDBUILT TEST_EXEC foo)

Whilst 'foo' is a target, it is not of type 'EXECUTABLE' and so CMake
cannot generate its full path from $<TARGET_FILE:foo> or otherwise
automatically resolve its path.

Add a custom property to targets created by cet_script that holds the
absolute path to the "built" script. Use this in cet_test to identify
use of a cet_script and populate the test executable path accordingly.
  • Loading branch information
drbenmorgan committed Jun 14, 2019
1 parent cc9afa1 commit f9406df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
33 changes: 18 additions & 15 deletions Modules/CetMake.cmake
Expand Up @@ -19,31 +19,31 @@
# [EXCLUDE <ignore these files>] )
#
# If USE_PRODUCT_NAME is specified, the product name will be prepended
# to the calculated library name
# to the calculated library name
# USE_PRODUCT_NAME and LIBRARY_NAME are mutually exclusive
#
# NOTE: if your code includes art plugins, you MUST use art_make
# instead of cet_make: cet_make will ignore all known plugin code.
#
# cet_make_library( LIBRARY_NAME <library name>
# SOURCE <source code list>
# [LIBRARIES <library list>]
# cet_make_library( LIBRARY_NAME <library name>
# SOURCE <source code list>
# [LIBRARIES <library list>]
# [WITH_STATIC_LIBRARY]
# [NO_INSTALL] )
#
# Make the named library.
#
# cet_make_exec( <executable name>
# [SOURCE <source code list>]
# cet_make_exec( <executable name>
# [SOURCE <source code list>]
# [LIBRARIES <library link list>]
# [USE_BOOST_UNIT]
# [NO_INSTALL] )
#
# Build a regular executable.
#
# cet_script( <script-names> ...
# [DEPENDENCIES <deps>]
# [NO_INSTALL]
# [DEPENDENCIES <deps>]
# [NO_INSTALL]
# [GENERATED]
# [REMOVE_EXTENSIONS] )
#
Expand All @@ -54,7 +54,7 @@
# command, for example); otherwise it will be copied from
# ${CMAKE_CURRENT_SOURCE_DIR}.
#
# If REMOVE_EXTENSIONS is specified, extensions will be removed from script names
# If REMOVE_EXTENSIONS is specified, extensions will be removed from script names
# when they are installed.
#
# NOTE: If you wish to use one of these scripts in a CUSTOM_COMMAND,
Expand Down Expand Up @@ -262,14 +262,14 @@ macro( cet_make )
set(cet_make_library_name ${cet_make_name})
endif()
_cet_debug_message("cet_make: building library ${cet_make_library_name} for ${CMAKE_CURRENT_SOURCE_DIR}")
if(CM_LIBRARIES)
if(CM_LIBRARIES)
cet_make_library( LIBRARY_NAME ${cet_make_library_name}
SOURCE ${cet_make_library_src}
LIBRARIES ${cet_liblist} )
else()
else()
cet_make_library( LIBRARY_NAME ${cet_make_library_name}
SOURCE ${cet_make_library_src} )
endif()
endif()
#message( STATUS "cet_make debug: library ${cet_make_library_name} will be installed in ${${CMAKE_PROJECT_NAME}_lib_dir}")
else( )
_cet_debug_message("cet_make: no library for ${CMAKE_CURRENT_SOURCE_DIR}")
Expand All @@ -281,7 +281,7 @@ macro( cet_make )
if( NOT CM_NO_DICTIONARY AND dictionary_header AND dictionary_xml )
_cet_debug_message("cet_make: found dictionary in ${CMAKE_CURRENT_SOURCE_DIR}")
set(cet_file_list ${cet_file_list} ${dictionary_xml} ${dictionary_header} )
if(CM_LIBRARIES)
if(CM_LIBRARIES)
build_dictionary( DICTIONARY_LIBRARIES ${cet_liblist} )
else()
build_dictionary( )
Expand Down Expand Up @@ -343,7 +343,7 @@ macro( cet_make_library )
else()
cet_add_to_library_list( ${CML_LIBRARY_NAME})
##_cet_debug_message( "cet_make_library: ${CML_LIBRARY_NAME} will be installed in ${${CMAKE_PROJECT_NAME}_lib_dir}")
install( TARGETS ${CML_LIBRARY_NAME}
install( TARGETS ${CML_LIBRARY_NAME}
RUNTIME DESTINATION ${${CMAKE_PROJECT_NAME}_bin_dir}
LIBRARY DESTINATION ${${CMAKE_PROJECT_NAME}_lib_dir}
ARCHIVE DESTINATION ${${CMAKE_PROJECT_NAME}_lib_dir}
Expand All @@ -361,7 +361,7 @@ macro( cet_make_library )
if( CML_NO_INSTALL )
#message(STATUS "cet_make_library debug: ${CML_LIBRARY_NAME}S will not be installed")
else()
install( TARGETS ${CML_LIBRARY_NAME}S
install( TARGETS ${CML_LIBRARY_NAME}S
RUNTIME DESTINATION ${${CMAKE_PROJECT_NAME}_bin_dir}
LIBRARY DESTINATION ${${CMAKE_PROJECT_NAME}_lib_dir}
ARCHIVE DESTINATION ${${CMAKE_PROJECT_NAME}_lib_dir}
Expand Down Expand Up @@ -391,6 +391,9 @@ macro (cet_script)
NAME_AS_TARGET
DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
)
# Set a property for location of copied script
set_property(TARGET ${target} PROPERTY CET_SCRIPT "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}")

# Install in product if desired.
if (NOT CS_NO_INSTALL)
install(PROGRAMS "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}"
Expand Down
8 changes: 7 additions & 1 deletion Modules/CetTest.cmake
Expand Up @@ -532,7 +532,13 @@ function(cet_test CET_TARGET)
"TEST_EXEC without HANDBUILT")
endif()
if(TARGET ${CET_TEST_EXEC})
set(CET_TEST_EXEC $<TARGET_FILE:${CET_TEST_EXEC}>)
get_target_property(__cet_script_exe ${CET_TEST_EXEC} CET_SCRIPT)
if(__cet_script_exe)
set(CET_TEST_EXEC "${__cet_script_exe}")
message(STATUS "${CET_TEST_EXEC}: ${__cet_script_exe}")
else()
set(CET_TEST_EXEC $<TARGET_FILE:${CET_TEST_EXEC}>)
endif()
endif()
else()
# This covers cases when we build the target, PREBUILT check in next
Expand Down

0 comments on commit f9406df

Please sign in to comment.