[CMake] External project source

Eric Noulard eric.noulard at gmail.com
Mon Feb 13 02:47:45 EST 2012


2012/2/13 Nicholas Yue <yue.nicholas at gmail.com>:
> Hi,
>
>    There is an existing project I have access to that already have CMake
> configuration file but the way it is written requires alot of preprocessing
> steps (python, shell etc) before it is usable.
>
>    I wanted to investigate a cleaner (truer to CMake original design
> purpose) usage of CMake,
>
>    So, I have an  original-project directory which contains both the source
> and the CMakeLists.txt in a nested directory structure.
>
>    I want to create my own CMake hierarchy (structure the same way) but
> reference the source code in the original-project directory location.
>
>    How do I tell CMake to refer to source code at some other top level
> directory as a starting point.
>
>    Is there such a concept in CMake ?

I am not sure to fully understand you request but in a CMakeLists.txt
you can perfectly
refer to source located outside the directory the CMakeLists.txt is in,
you can use either relative or absolute path and do something like:

add_executable(NiceTarget ../../relpath/to/source.c
${CMAKE_SOURCE_DIR}/abspath/to/another.c)

this is usually a bad idea but this should work.

Now that said if you do that for compatibility purpose in order to
maintain the legacy build
before doing the switch to "genuine" CMake build then may be using a
VCS like git would
be a better way to go.

Using git (or other easy branching VCS) you can work on your
"genuine-CMake" branch whithout
trouble while merging from the origin as it evolves. Using this,
people wanting to try your branch
could either pull it or you can create patches against origin.

>    At the risks of confusing matter, my closest example would be something
> vaguely resembling VPATH

There is no such thing in CMake, as far as I know,
source files specified with relative path are searched
1) in the build tree,
2) in the source tree.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list