[CMake] INCLUDE cannot find file
Shiqing Fan
fan at hlrs.de
Tue Oct 2 08:19:45 EDT 2007
Eric Noulard wrote:
> 2007/10/2, Dizzy <dizzy at roedu.net>:
>
>> On Tuesday 02 October 2007 13:18:15 Shiqing Fan wrote:
>>
>>
>>> And some thing about why I use it. The project has a complicated file
>>> structure. Take the above structure as an example, both sub1 ans sub2
>>> have source files for generating a library on top level.
>>> And on
>>> different platforms, not all the files are necessary. Yes, I could use
>>> SET(SOURCE ${SOURCE} file1 file2....) with relative path, but if the we
>>> have 4 or 5 levels of subdirectory, this is going to be a nightmare,
>>> because we have to manage all the source files on top level for
>>> different platforms.
>>>
>> But if the files are scattered randomly in various 4 level directories, some
>> files that may need to be used on a platforms, others than dont, then you
>> already have a nightmare and using SET() just shows the nightmare. Try to
>> describe in more detail your project structure and also the simplest solution
>> you can think of (even that it doesn't work directly with cmake like you
>> think of it).
>>
>
> Having several level of directories from which you don't want to
> ADD_SUBDIRECTORY
> reveals a probably flawed source setup.
>
> However you may easily do the following:
>
> in toplevel/CMakeLists.txt
>
> SET(LIB_SOURCES "")
>
> INCLUDE(sub1/source_definitions.cmake)
> SET(LIB_SOURCES "${LIB_SOURCES} ${SUB1_SOURCES}"
>
> INCLUDE(sub1/sub2/source_definitions.cmake)
> SET(LIB_SOURCES "${LIB_SOURCES} ${SUB1_SUB2_SOURCES}"
>
> etc...
> ADD_LIBRARY(toplib ${LIB_SOURCES})
>
> SUBx_SUBy_SOURCES var is defined in INCLUDE(source_definitions.cmake)
> as you already figured out SOURCES should be specified with as
> relative to toplevel ie. subx/suby/<filename>
>
Yes, this is what I'm currently using.
INCLUDE (sub1/CMakeLists.txt)
FOREACH (FILE ${SUB1_FILES})
SET (SOURCE_FILES ${SOURCE_FILES} sub1/${FILE})
ENDFOREACH (FILE)
The for-loop will add a relative path to each file in the subdirectory.
The problem is that I have to do it for each subdirectories on every
level except for the bottom level.
> I think this would both clearer and fits your needs.
> If you are not afraid of doing a bit of CMake MACRO
> you should even be able to do MACROify with something like:
>
> FILE(GLOB_RECURSE TOBE_INCLUDED "source_def*.cmake")
> FOREACH(SUBFILE ${TOBE_INCLUDED})
> GET_FILENAME_COMPONENT(DIRNAME ${SUBFILE} PATH)
> INCLUDE(${SUBFILE})
> /* find way to change DIRNAME=sub1/sub2/sub3 to
> SOURCE_PREFIX SUB1_SUB2_SUB3_SOURCES */
> SET(SOURCE ${SOURCE} ${${SOURCE_PREFIX}})
> ENDFOREACH()
>
This is also a good choice, but too tricky for me at moment. I'll try to
make it work for me.
Thanks to all,
Shiqing
--
--------------------------------------------------------------
Shiqing Fan
http://www.hlrs.de/people/fan
High Performance Computing Tel.: +49 711 685 87234
Center Stuttgart (HLRS) Fax.: +49 711 685 65832
POSTAL:Nobelstrasse 19 email: fan at hlrs.de
ACTUAL:Allmandring 30
70569 Stuttgart
More information about the CMake
mailing list