[CMake] multiple source directories

Martin Kupke martin.kupke at novero.com
Wed Sep 28 06:59:05 EDT 2011


I have a same problem (even relative paths should not be used, as I 
understood from documentation) and I fixed my problem by setting a 
variable in the /root/CMakeLists.txt e.g.
set( MY_PROJECT_PROG1 ${CMAKE_CURRENT_SOURCE_DIR}/prog1 )
set( MY_PROJECT_PROG2 ${CMAKE_CURRENT_SOURCE_DIR}/prog2 )
The subprojects / subfolders always inherit the settings / variables, so 
you can work with ${MY_PROJECT_PROG1} in your /root/prog1/CMakeLists.txt.

Martin

On 28.09.11 12:51, pellegrini wrote:
> Hi all,
>
> I have a project with the following structure:
>
> root/
>      CMakeLists.txt
>      prog1/
>          CMakeLists.txt
>          Src/
>              file1.f90
>      prog2/
>          CMakeLists.txt
>          Src/
>              file2.f90
>
> where prog1, prog2 are individual projects.
>
> I would like to add file1.90 to the build process of prog2. To do so, in
> the CMakeLists.txt file of prog2 project, I put:
>
>      set(SOURCES ../../prog1/Src/file1.f90
>                              Src/file2.f90)
> and further
>      add_executable(prog2 ${SOURCES})
>
> when compiling with CMake I get the following error:
>
> ##############################################
> CMake Error at CMakeLists.txt:35 (add_executable):
>    Cannot find source file:
>
>      ../../prog1/Src/file1.f90
>
>    Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm
> .hpp  .hxx .in .txx
> ###############################################
>
> It seems that CMake cna not deal with relative path when declaring the
> sources for a project. I tried using the option CMAKE_USE_RELATIVE_PATHS
> but it might not be defined for that purpose as it did not solve the
> problem. Would you have any idea how to solve that problem ?
>
> thanks a lot
>
> Eric
>
>
>
>

-- 

------------------------------------------------------------------------

*martin kupke*

can diagnostics engineer | senior software developer

*m*:+49.151.5511.3632| *e*:martin.kupke at novero.com 
<mailto:martin.kupke at novero.com>

skype:martin.kupke_novero | w:www.novero.com <http://www.novero.com>

novero GmbH
meesmannstr.103 | 44807 Bochum | germany


novero gmbh | parsevalstr. 7 a | 40468 düsseldorf | germany | 
amtsgericht düsseldorf | hrb 58283 | umsatzsteueridentifikationsnummer: 
de 814973142 | geschäftsführender gesellschafter: razvan olosu



More information about the CMake mailing list