[CMake] Simple CMake sample

Michael Wild themiwi at gmail.com
Tue Feb 12 08:41:51 EST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 12Feb, 2008, at 14:25, David Sveningsson wrote:

> Michael Wild skrev:
>> quite simply, e.g.:
>> foo/CMakeLists.txt:
>> ###################
>> PROJECT(foo) # project name
>> ADD_SUBDIRECTORY( vendor/bar ) # add subdir
>> INCLUDE_DIRECTORIES( include vendor/bar/include ) # add to include  
>> path
>> ADD_EXECUTABLE(
>>  foo                                          # build executable foo
>>  src/source1.cpp                   # from these sources
>>  src/source2.cpp
>>  src/component_x/source_x.cpp
>> )
>> TARGET_LINK_LIBRARIES(
>>  foo                            # to foo link
>>  bar                           # library bar which is in vendor/bar
>> )
>> ###################
>> vendor/bar/CMakeLists.txt
>> ###################
>> PROJECT( bar) # if you want to
>> INCLUDE_DIRECTORIES( include )
>> ADD_LIBRARY(
>>  bar
>>  src/source1.cpp
>> )
>> ###################
>> hth
>> Michael
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>
> Thanks, I had no idea you could add the path next to the  
> sourcefiles. Maybe someone should put this or something similar on  
> the CMake wiki, I mean I can't be the first one to have similar  
> questions.
>

I couldn't find it in the man-page, but actually this is probably the  
most intuitive behavior I can think of and really would expect. Why  
should a relative path NOT be ok? What might be a bit surprising  
though is the fact that CMake find the bar-library, but this is thanks  
to the ADD_SUBDIRECTORY command, which propagates the target name up  
to the calling CMakeLists.txt.


Michael



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkexoiAACgkQyAe0BK8NufNb8QCfTFnQlPNwylV97UvAZVTphA9v
0t8Ani+a3uqb25ZfrMbxoaeA65CTCWDp
=1PMl
-----END PGP SIGNATURE-----


More information about the CMake mailing list