ecbuild icon indicating copy to clipboard operation
ecbuild copied to clipboard

[Question] Accessing executable build location outside of `ecbuild`

Open StegmannJCSDA opened this issue 2 years ago • 2 comments

I am working on updating a legacy project that will use ecbuild to build multiple executables in the following way:

ecbuild_add_executable( TARGET app
                        SOURCES ${app_src_files}
                        LIBS crtm )

In the past this was done with local makefiles that built the executables in their source directory. I would like to be able to create a (likely Python) script that links all the generated executables into a case directory, together with some case-specific input data.

To this end, the Python script would need to know the path of the executables built with ecbuild.

Is there an elegant way to do this?

StegmannJCSDA avatar Sep 16 '22 16:09 StegmannJCSDA

This is really independent of ecbuild, but rather a general CMake question.

The older CMake way was to get the LOCATION property from a target via

get_target_property(<var> <target> LOCATION)

but that has been deprecated for non-imported targets, see Policy 0026. The recommendation is to use the $<TARGET_FILE:executable> generator expression in combination with file(generate).

wdeconinck avatar Sep 19 '22 08:09 wdeconinck

This is really independent of ecbuild, but rather a general CMake question.

Yes, indeed.

Thank you, I will have a closer look at the documentation. Something like this will probably work:

file(GENERATE OUTPUT location_file CONTENT "$<TARGET_FILE:executable>")

StegmannJCSDA avatar Sep 19 '22 19:09 StegmannJCSDA