Use a separate target to copy files to build folder

Several operations was attached to the POST_BUILD custom command of the ResInsight target. The number of characters in this command exceeded the limit on Windows, and error message "line too long" was displayed on GitHub actions.

Suggested solution to copy files into build folder
- add new target ResInsightDummyTarget used to find full path to build folder
- add new target PreBuildFileCopy for file copy
- add all copy operations as a list of cmake commands on PreBuildFileCopy
This commit is contained in:
Magne Sjaastad 2023-12-11 08:39:09 +01:00
parent ea56ceaea0
commit 7fb8de2204
2 changed files with 35 additions and 7 deletions

View File

@ -380,15 +380,33 @@ else()
endforeach(OPENVDS_LIB_NAME)
endif(MSVC)
# Copy dependencies to make it possible to run ResInsight from the build folder
foreach(FILE_TO_COPY ${RI_FILENAMES})
add_custom_command(
TARGET ResInsight
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FILE_TO_COPY}
$<TARGET_FILE_DIR:ResInsight>
# create an empty library target that will be used to copy files to the build
# folder
add_library(ResInsightDummyTarget EXCLUDE_FROM_ALL empty.cpp)
set_property(TARGET ResInsightDummyTarget PROPERTY FOLDER "FileCopyTargets")
# create a custom target that copies the files to the build folder
foreach(riFileName ${RI_FILENAMES})
list(
APPEND
copyCommands
COMMAND
${CMAKE_COMMAND}
-E
copy_if_different
${riFileName}
$<TARGET_FILE_DIR:ResInsightDummyTarget>
)
endforeach()
add_custom_target(
PreBuildFileCopy
COMMENT "PreBuildFileCopy step: copy runtime files into build folder"
${copyCommands}
)
set_property(TARGET PreBuildFileCopy PROPERTY FOLDER "FileCopyTargets")
# Make ResInsight depend on the prebuild target.
add_dependencies(ResInsight PreBuildFileCopy)
# Generate Python code in a target that is part of ALL_BUILD and depends on
# ResInsight

View File

@ -0,0 +1,10 @@
//
// This empty file is used by ResInsightDummyTarget
//
// Creating a dummy target with an empty file is used to have a different target than ResInsight.
// This target is used to find the full path to the build folder.
//
// $<TARGET_FILE_DIR:ResInsightDummyTarget>
//
// If we use the ResInsight target ($<TARGET_FILE_DIR:ResInsight>), we get a circular dependency.
//