Discussion:
[CMake] Recursive list append
Diablo 666
2010-07-06 08:06:02 UTC
Permalink
Hi,

say I create a list in the top level CMakeLists.txt and call a subdirectory. The subdirectory should add some entries to the list, then the top level should use the full list. How can I accomplish this?

Best regards,
Andreas

_________________________________________________________________
http://redirect.gimas.net/?n=M1007xHM2
Räumen Sie Ihr Postfach auf - ganz einfach mit Hotmail!
Marcel Loose
2010-07-06 08:17:42 UTC
Permalink
Hi Andreas,

Use 'set(<variable> <value> PARENT_SCOPE])'. This will set the variable
in the scope directly above the current scope. Remember that each
add_subdirectory() will create a new scope.

HTH,
Marcel Loose.

On Tue, 2010-07-06 at 10:06 +0200, Diablo 666 wrote:
> Hi,
>
> say I create a list in the top level CMakeLists.txt and call a
> subdirectory. The subdirectory should add some entries to the list,
> then the top level should use the full list. How can I accomplish
> this?
>
> Best regards,
> Andreas
>
>
> ______________________________________________________________________
> Räumen Sie Ihr Postfach auf - ganz einfach mit Hotmail!
> _______________________________________________
> 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.cm
Diablo 666
2010-07-06 08:41:43 UTC
Permalink
If I use SET with PARENT_SCOPE, wouldn't this delete old entries? Say I have more than one subdirectory. Can I append entries from both subdirectories this way?

_________________________________________________________________
http://redirect.gimas.net/?n=M1007xHMTL4
Künftig E-Mails über Hotmail ohne Werbung versenden!
Michael Wild
2010-07-06 08:49:58 UTC
Permalink
On 6. Jul, 2010, at 10:41 , Diablo 666 wrote:

>
> If I use SET with PARENT_SCOPE, wouldn't this delete old entries? Say I have more than one subdirectory. Can I append entries from both subdirectories this way?


CMakeLists.txt:
###############
set(some_list val1 val2 val3)
add_subdirectory(subdir)
message(STATUS "some_list = ${some_list}")

subdir/CMakeLists.txt:
######################
# append in local scope
list(APPEND some_list val4 val5 val6)
# set in parent scope
set(some_list "${some_list}" PARENT_SCOPE)


Michael
Diablo 666
2010-07-06 08:58:18 UTC
Permalink
> CMakeLists.txt:
> ###############
> set(some_list val1 val2 val3)
> add_subdirectory(subdir)
> message(STATUS "some_list = ${some_list}")
>
> subdir/CMakeLists.txt:
> ######################
> # append in local scope
> list(APPEND some_list val4 val5 val6)
> # set in parent scope
> set(some_list "${some_list}" PARENT_SCOPE)


this is ugly. Really ugly. I like it :-D

Thanks a lot!

_________________________________________________________________
http://redirect.gimas.net/?n=M1007xHMTL4
Künftig E-Mails über Hotmail ohne Werbung versenden!
Verweij, Arjen
2010-07-06 16:55:22 UTC
Permalink
Hi,

We're experiencing two problems with creating static libraries through cmake on our AIX system.

The first one is that a cmake based build environment will come up with 64-bit XCOFF, but ar and friends won't play ball unless you add -X64. I suppose this issue has just been overlooked and is in fact minor.

The other problem is that even though I have added the below workaround referenced in a thread from July '08, "ar cr" will choke on the amount or objects I'm feeding it. I'm sure this is a problem with the ar itself and not cmake, but I would be interested to learn of a possible workaround. It works fine for smaller archives.

Thanks,
Arjen

SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -X64 cr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> -X64 r <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -X64 <TARGET>")
SET(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_C_ARCHIVE_CREATE})
SET(CMAKE_CXX_ARCHIVE_APPEND ${CMAKE_C_ARCHIVE_APPEND})
SET(CMAKE_CXX_ARCHIVE_FINISH ${CMAKE_C_ARCHIVE_FINISH})
SET(CMAKE_Fortran_ARCHIVE_CREATE ${CMAKE_C_ARCHIVE_CREATE})
SET(CMAKE_Fortran_ARCHIVE_APPEND ${CMAKE_C_ARCHIVE_APPEND})
SET(CMAKE_Fortran_ARCHIVE_FINISH ${CMAKE_C_ARCHIVE_FINISH})
Verweij, Arjen
2010-07-07 15:26:17 UTC
Permalink
Hi,

Apparently it had to do with the setting for "ncargs". Increasing it to 256 (blocks of 4K) solved it.

Regards,
Arjen

>-----Original Message-----
>From: cmake-***@cmake.org [mailto:cmake-***@cmake.org] On Behalf
>Of Verweij, Arjen
>Sent: dinsdag 6 juli 2010 18:55
>To: ***@cmake.org
>Subject: [CMake] problems with creating static library on aix
>
>Hi,
>
>We're experiencing two problems with creating static libraries through
>cmake on our AIX system.
>
>The first one is that a cmake based build environment will come up with
>64-bit XCOFF, but ar and friends won't play ball unless you add -X64. I
>suppose this issue has just been overlooked and is in fact minor.
>
>The other problem is that even though I have added the below workaround
>referenced in a thread from July '08, "ar cr" will choke on the amount
>or objects I'm feeding it. I'm sure this is a problem with the ar itself
>and not cmake, but I would be interested to learn of a possible
>workaround. It works fine for smaller archives.
>
>Thanks,
>Arjen
>
>SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -X64 cr <TARGET> <LINK_FLAGS>
><OBJECTS>")
>SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> -X64 r <TARGET> <LINK_FLAGS>
><OBJECTS>")
>SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -X64 <TARGET>")
>SET(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_C_ARCHIVE_CREATE})
>SET(CMAKE_CXX_ARCHIVE_APPEND ${CMAKE_C_ARCHIVE_APPEND})
>SET(CMAKE_CXX_ARCHIVE_FINISH ${CMAKE_C_ARCHIVE_FINISH})
>SET(CMAKE_Fortran_ARCHIVE_CREATE ${CMAKE_C_ARCHIVE_CREATE})
>SET(CMAKE_Fortran_ARCHIVE_APPEND ${CMAKE_C_ARCHIVE_APPEND})
>SET(CMAKE_Fortran_ARCHIVE_FINISH ${CMAKE_C_ARCHIVE_FINISH})
>_______________________________________________
>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
Michael Wild
2010-07-06 08:17:56 UTC
Permalink
On 6. Jul, 2010, at 10:06 , Diablo 666 wrote:

>
> Hi,
>
> say I create a list in the top level CMakeLists.txt and call a subdirectory. The subdirectory should add some entries to the list, then the top level should use the full list. How can I accomplish this?
>
> Best regards,
> Andreas

Either use the PARENT_SCOPE option of the SET() command or, IMHO preferably, use a global property like this:

CMakeLists.txt:
###############
set_property(GLOBAL PROPERTY some_super_property val1 val2 val3)
add_subdirectory(subdir)
get_property(some_super_list GLOBAL PROPERTY some_super_property)
message(STATUS "some_super_list = ${some_super_list}")

subdir/CMakeLists.txt:
######################
set_property(GLOBAL APPEND PROPERTY some_super_property val4 val5 val6)


HTH

Michael
Continue reading on narkive:
Loading...