I have a script called "install_copy_dlls.cmake", which is called to execute from top level cmake file as shown below.
INSTALL(SCRIPT "install_copy_dlls.cmake")
And, I have a variable named "USE_OSG_STATIC" which is set to ON if I use Statically compiled OpenSceneGraph and set of OFF if I use Dynamically compiled OpenSceneGraph.
I need to use this variable inside install_copy_dlls.cmake script.
so, here is how install_copy_dlls.cmake file should look like.
copy other required dlls...
if(NOT USE_OSG_STATIC) //if dynamic OSG
copy osg dlls
here, I try to use "message" to print USE_OSG_STATIC variable and it doesn't print anything.
Can anyone explain me why I can not use variables in Script file?
I found a simpler solution: set the variable in a preceding install() call:
This ends up rendered into the cmake_install script roughly as:
which is exactly what you need.
install(SCRIPT ...)
command works like cmake -P. So there is no variables forwarded from parent script to child (until you explicitly define one):Using
CMakeLists.txt
:Forward to child process:
Solution #1 (forwarding)
Using
install(CODE ...)
command you can define variable forrun.cmake
script:Solution #2 (configuring)
You can configure install script using configure_file command: