Using a cache variable seems not required. A function creates a new scope
and inherit a copy of all variables defined in the upper scope.
So, by adding a set command using PARENT_SCOPE in your function you can
update the variable in the parent scope:
      function(addTest targetName)
                # create the executable with all the souces
                add_executable(${targetName} ${ARGN})
                list(APPEND allTestsList ${targetName})
                *set (allTestsList  ${allTestsList} PARENT_SCOPE) *
                message("inside addTestFunction. allTestsList: "
${allTestsList})
        endfunction()

Le jeu. 27 sept. 2018 à 12:43, Romain LEGUAY <romain.leg...@gmail.com> a
écrit :

> Hello everyone,
>
> I try to append a string (target name) on a list inside a function called
> in other CMakeLists.
>
> I have the following project’s tree:
>
> ├── CMakeLists.txt
> ├── test
>     ├── CMakeLists.txt
>     └── app
>         ├── CMakeLists.txt
>         ├── appA
>         │   ├── CMakeLists.txt
>         │   └── main.cpp
>         └── appB
>             ├── CMakeLists.txt
>             └── main.cpp
>
> Inside the test/CMakeLists.txt, I defined an internal variable like this:
>         set(allTestsList "" CACHE INTERNAL "All executable tests.'')
> And my function:
>         function(addTest targetName)
>                 # create the executable with all the souces
>                 add_executable(${targetName} ${ARGN})
>                 list(APPEND allTestsList ${targetName})
>                 message("inside addTestFunction. allTestsList: "
> ${allTestsList})
>         endfunction()
>
> I call this function inside the test/app/appA and test/app/appB
> CMakeLists.txt like this:
>         addTest(appA main.cpp)
>         addTest(appB main.cpp)
>
> I expected to have as final result:
> inside addTestFunction. allTestsList: appA;appB
>
> But I only have:
> inside addTestFunction. allTestsList: appB
>
> I suspect that a new variable is created at each call of the function.
>
> Is it possible to use a global variable? (I tried to use PARENT_SCOPE with
> no success).
>
> Thank you,
>
> Romain
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

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

Reply via email to