Select Git revision
Forked from
Computing / cbmroot
Source project has a limited visibility.
HelperMacros.cmake NaN GiB
################################################################################
# Exchange file extention of file in list from ext1 to ext2,
# only if the resulting file exists in CMAKE_CURRENT_SOURCE_DIR,
# and assign the newly created list to 'output'.
# The input list is not changed at all
# Ex: fair_change_file_extension_ifexists(*.cxx *.h "${TRD_SRCS}" TRD_HEADERS)
# Ex: fair_change_extensions_if_exists(.cxx .h FILES "${sources}" OUTVAR headers)
################################################################################
function(change_extensions_if_exists ext1 ext2)
cmake_parse_arguments(ARGS "" "OUTVAR" "FILES" ${ARGN})
set(required_args "FILES;OUTVAR")
foreach(required_arg IN LISTS required_args)
if(NOT ARGS_${required_arg})
message(FATAL_ERROR "change_extensions_if_exists is missing a required argument: ${required_arg}")
endif()
endforeach()
# Loop over all files, check if file has the correct extension
# and exchange the file extension if it is correct
foreach(file ${ARGS_FILES})
set(newFile "")
get_filename_component(_ext ${file} LAST_EXT)
if (NOT ${_ext} MATCHES ${ext1})
message(FATAL_ERROR "File ${file} has not the expected extension ${ext1}")
endif()
get_filename_component(_file ${file} NAME_WLE)
get_filename_component(_dir ${file} DIRECTORY)
if(NOT _dir)
set(newfile ${_file}${ext2})
else()
set(newfile ${_dir}/${_file}${ext2})
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${newfile})
list(APPEND result ${newfile})
endif()
endforeach()
set(${ARGS_OUTVAR} ${result} PARENT_SCOPE)
endfunction()