Skip to content

Commit

Permalink
add an empty library to be able to use $<TARGET_FILE_DIR:
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Dec 10, 2023
1 parent b5d8c40 commit c140f3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 4 additions & 9 deletions ApplicationExeCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,26 +380,21 @@ else()
endforeach(OPENVDS_LIB_NAME)
endif(MSVC)

# create an empty library target that will be used to copy files to the build folder
add_library(ResInsightFileCopyTargets EXCLUDE_FROM_ALL empty.cpp)
set_property(TARGET ResInsightFileCopyTargets PROPERTY FOLDER "FileCopyTargets")


# create the build folder using the configuration name(Debug, Relese, ...) before copying files there
add_custom_target(build-time-make-directory ALL
COMMAND ${CMAKE_COMMAND} -E make_directory $<CONFIGURATION>)

# Copy dependencies to make it possible to run ResInsight from the build folder
foreach(full_file_name ${RI_FILENAMES})
# Get the filename from the full path.
get_filename_component(file_name ${full_file_name} NAME)
add_custom_target( prebuild_${file_name}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${full_file_name} .
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${full_file_name} $<TARGET_FILE_DIR:ResInsightFileCopyTargets>
)

# My application depends on the each pre-build target.
add_dependencies( ResInsight prebuild_${file_name} )

# The pre-build target depends on the build-time-make-directory target to make sure the directory exists.
add_dependencies( prebuild_${file_name} build-time-make-directory )

set_property(TARGET prebuild_${file_name} PROPERTY FOLDER "FileCopyTargets")

endforeach()
Expand Down
10 changes: 10 additions & 0 deletions ApplicationExeCode/empty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// This empty file is used by ResInsightFileCopyTargets
//
// 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:ResInsightFileCopyTargets>
//
// If we use the ResInsight target ($<TARGET_FILE_DIR:ResInsight>), we get a circular dependency.
//

0 comments on commit c140f3a

Please sign in to comment.