[CMake] How to store function definitions?

Eric Noulard eric.noulard at gmail.com
Sat Oct 25 11:38:31 EDT 2014


2014-10-25 14:11 GMT+02:00 Zé <jose.passes at gmx.com>:

> I've defined a small function that helps add unit test definitions in a
> concise manner.  I would like to store this function on a dedicated file to
> decluter the CMakeLists.txt file where that function is currently defined.
> Can anyone tell me what's the best way to store custom function definitions
> within a project tree?
>

I don't know whether if there is "THE" best way but my habit is the
following:

put all custom cmake scripts into a project subdir call
<PROJECT_ROOT>/cmake/ or sometimes <PROJECT_ROOT>/devel-scripts because I
put there other development oriented scripts written in
CMake, shell, python etc...

Then in my main CMakeLists.txt I add the dir to the CMake module path:

# Add project source dir as module path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/devel-scripts)

then when I need the macros defined in say "MyTestTools.cmake" I do:

include(MyTestTools.cmake)


I don't really know if it's the best way, but it works ok and makes it easy
to add more custom macro files when needed.


-- 
Erk
L'élection n'est pas la démocratie -- http://www.le-message.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141025/11d58f9f/attachment.html>


More information about the CMake mailing list