[CMake] Variable target name visible at the top level

2012-10-26 Thread Vyacheslav Karamov

Hi All!

I have project with the structure similar to this

worker
 | |
 | chatterbox
 | ||
 | |CMakeLists.txt
 | |
 | externals
 | ||
 | |sndlib
 | |   |
 | |   CMakeLists.txt
 | CMakeLists.txt
 |
 CMakeLists.txt



$ cat worker/CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

add_subdirectory(externals)
add_subdirectory(chatterbox)

If I set sndlib target as a variable

set (snd_lib sndlib)
add_library(${snd_lib} SHARED ...)

variable ${snd_lib} is undefined at the parent scope, i.e. I can't use 
${snd_lib} in chatterbox/ CMakeLists.txt


target_link_libraries(chatterbox  ${snd_lib})  # ${snd_lib} is empty!

How to handle this situation in a proper way?








--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Variable target name visible at the top level

2012-10-26 Thread Eric Noulard
2012/10/26 Vyacheslav Karamov ubuntul...@yandex.ru:
 Hi All!

 I have project with the structure similar to this

 worker
  | |
  | chatterbox
  | ||
  | |CMakeLists.txt
  | |
  | externals
  | ||
  | |sndlib
  | |   |
  | |   CMakeLists.txt
  | CMakeLists.txt
  |
  CMakeLists.txt



 $ cat worker/CMakeLists.txt

 cmake_minimum_required(VERSION 2.6)

 add_subdirectory(externals)
 add_subdirectory(chatterbox)

 If I set sndlib target as a variable

 set (snd_lib sndlib)
 add_library(${snd_lib} SHARED ...)

 variable ${snd_lib} is undefined at the parent scope, i.e. I can't use
 ${snd_lib} in chatterbox/ CMakeLists.txt

 target_link_libraries(chatterbox  ${snd_lib})  # ${snd_lib} is empty!

From your description this is strange because 'chatterbox'
is a subdir of 'worker' where snd_lib has been defined so it should be
visible, I guess...

unless you define the snd_lib var AFTER you
add_subdirectory(chatterbox)

since add_subdirectory process subdir first you must define
variable you need before add_subdirectory.

 How to handle this situation in a proper way?

Define it at the scope it ought to be ?
or use
 set (snd_lib sndlib PARENT_SCOPE)

but again I think your problems comes from the fact
your defined your var after add_subdirectory.

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Variable target name visible at the top level

2012-10-26 Thread Vyacheslav Karamov

Thank you, but if I need variable two level up?

26.10.2012 12:07, Rolf Eike Beer пишет:

On Fr., 26. Okt. 2012 10:22:51 CEST, Vyacheslav Karamov ubuntul...@yandex.ru 
wrote:


Hi All!

I have project with the structure similar to this
set (snd_lib sndlib)
add_library(${snd_lib} SHARED ...)
How to handle this situation in a proper way?

set(... PARENT_SCOPE)

This will propagate the variable one level up.

Eike


--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Variable target name visible at the top level

2012-10-26 Thread Eric Noulard
2012/10/26 Vyacheslav Karamov ubuntul...@yandex.ru:
 Thank you, but if I need variable two level up?

you may be able to use a GLOBAL property
see:
cmake --help-command set_property

or may be a CACHE variable.

but from my point of view, it looks like you have a design issue.

Why would you need to jump scope like that?


-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Variable target name visible at the top level

2012-10-26 Thread Vyacheslav Karamov

26.10.2012 12:16, Eric Noulard пишет:

2012/10/26 Vyacheslav Karamov ubuntul...@yandex.ru:

Hi All!

I have project with the structure similar to this

worker
  | |
  | chatterbox
  | ||
  | |CMakeLists.txt
  | |
  | externals
  | ||
  | |sndlib
  | |   |
  | |   CMakeLists.txt
  | CMakeLists.txt
  |
  CMakeLists.txt



$ cat worker/CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

add_subdirectory(externals)
add_subdirectory(chatterbox)

If I set sndlib target as a variable

set (snd_lib sndlib)
add_library(${snd_lib} SHARED ...)

variable ${snd_lib} is undefined at the parent scope, i.e. I can't use
${snd_lib} in chatterbox/ CMakeLists.txt

target_link_libraries(chatterbox  ${snd_lib})  # ${snd_lib} is empty!

From your description this is strange because 'chatterbox'
is a subdir of 'worker' where snd_lib has been defined so it should be
visible, I guess...

unless you define the snd_lib var AFTER you
add_subdirectory(chatterbox)

since add_subdirectory process subdir first you must define
variable you need before add_subdirectory.

I have added externals before chatterbox, so

${snd_lib} should be defined in chatterbox.


How to handle this situation in a proper way?

Define it at the scope it ought to be ?
or use
  set (snd_lib sndlib PARENT_SCOPE)

but again I think your problems comes from the fact
your defined your var after add_subdirectory.

PARENT_SCOPE variable is visible only in a parent scope, not in a 
current one. But I need it in current scope, parent scope and scope 
above parent.


--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Variable target name visible at the top level

2012-10-26 Thread Eric Noulard
2012/10/26 Vyacheslav Karamov ubuntul...@yandex.ru:


 How to handle this situation in a proper way?

 Define it at the scope it ought to be ?
 or use
   set (snd_lib sndlib PARENT_SCOPE)

 but again I think your problems comes from the fact
 your defined your var after add_subdirectory.

 PARENT_SCOPE variable is visible only in a parent scope, not in a current
 one. But I need it in current scope, parent scope and scope above parent.

Then I guess you should try to use a global property or cached var.
Some example attached.

As you'll see both mechanism may achieve what you with varying bevahior.
If you want to learn the differences:

cmake --help-command get_property
cmake --help-command set_property
cmake --help-command set
-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


multi-scope-var-or-props.tgz
Description: GNU Zip compressed data
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake