[CMake] Re: How to update a variable inside a subfolder?

kitts kitts.mailinglists at gmail.com
Mon Jan 29 11:56:28 EST 2007


On Monday 29 Jan 2007 IST, kitts wrote:
> Is it possible to update a variable inside a subfolders CMakeLists.txt?
>
> It appears that the scope of the variable is limited to the current
> CMakeLists.txt but is possible to get the above behavior?

To explain a lil more:

I have the source code organized as shown below:

|-Source/
 |-x86/
 ||-CMakeLists.txt
 ||-arch.c
 ||-init.S
 ||-another.c
 +-coldfire/
 +-ppc/
 |-source1.c
 |-source2.c
 |-CMakeLists.txt

Source/CMakeLists.txt contains something like the following;

# MyModule contains useful macros like for listing the directories
# in a given folder; GET_DIR_LIST()
INCLUDE(MyModule)

#Get a list of dir names in the current dir
GET_DIR_LIST(SUPPORTED_ARCHS ${CMAKE_CURRENT_SOURCE_DIR})

SET(ARCH x86 CACHE STRING 
        "Select the architecture for which to build. Options are:
${SUPPORTED_ARCHS}"
        FORCE)

IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH})
ELSE(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH})
        MESSAGE(FATAL_ERROR "Unsupported architecture")
ENDIF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH})

SET(SRC_LST source1.c source2.c)

# Here I would like SRC_LST to be updated inside the subdir, however,
# SRC_LST has the complete list in the subdir not changes made are
# lost as it returns to this parent directory
ADD_SUBDIRECTORY(${ARCH})

ADD_LIBRARY(MyLib ${SRC_LST})

The file Source/x86/CMakeLists.txt only contains:

SET(SRC_LIST ${SRC_LIST} arch.c init.S startup.S)

I don't want to include these files directly in Source/CMakeLists.txt as
file names and the number of them varies from one arch to another. Depending 
on the complexity, they may further contain subfolders for easier code 
organization. Maintainers of the arch specific are different for each arch 
and id like to let them take responsibility with their folders.

The only solution I see is a mechanism in the arch subfolders to create a
file that will contain names of all the source files for that arch and
then include that file in the parent folder's CMakeLists.txt. But is
there a cleaner solution?
-- 
Cheers!
kitts


More information about the CMake mailing list