I’m creating a library with add_library(h5geo SHARED ${src_files_h5geo} ${include_files_h5geo}).
Then I need to get path to h5geo runtime library (for now I’m on Windows so I would like to get path to h5geo.dll)
During configuration step, these properties are input properties. So only usable if you have already set some value.
The final information is only available during generation step. For that purpose, you should use generator expressions like $<TARGET_PROPERTY:h5geo,RUNTIME_OUTPUT_NAME>.
Generator expressions are not usable everywhere, only when explicitly specified in the documentation of the commands. For example, install(CODE) does not support generator expressions.
In your case, the most simple way to achieve what you want is to generate a script using file(GENERATE) command and execute it using install(SCRIPT) command.
Is it necessary to setRUNTIME_OUTPUT_DIRECTORY target property before reading it? Or there is a default path (MSVC stores binaries at Release/Config folder inside buinding tree for example) that I can get using generator expression?
Cna’t understand. install(CODE "message(\"TARGET_FILE: $<TARGET_FILE:h5geo>\")") shows my library.
But if I put the same code to the script and call it install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/h5geopy-install.cmake) then it will literally print TARGET_FILE: $<TARGET_FILE:h5geo>
generator expression is used inside file(GENERATE ...):
configure_file(${CMAKE_SOURCE_DIR}/cmake/h5geopy-install.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/h5geopy-install.cmake
@ONLY
)
# $<CONFIG> at the end of filename is necessary for multiconfig generators
# such as MSVC or Ninja multiconfig (gives error without it:
# "Evaluation file to be written multiple times with different content."
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/h5geopy-install-$<CONFIG>.cmake
INPUT ${CMAKE_CURRENT_BINARY_DIR}/h5geopy-install.cmake
)
So for the first time I simply configure file and set marked with @ variables and after that I use file(GENERATE ...) where my $<TARGET_FILE:h5geo> transforms to path.