[CMake] Multiple install section from the same base folder

Eric Noulard eric.noulard at gmail.com
Tue Jul 12 03:19:45 EDT 2011


2011/7/12 Laszlo Papp <lpapp at kde.org>:
> Hi,
>
> I have just realized this snippet in my CMakeLists.txt file:
>
> install(FILES
>    atticamanager.h
>    authentication.h
>
>    DESTINATION ${INCLUDE_INSTALL_DIR}/gluon/player/lib
>    COMPONENT Devel
> )
>
> install(FILES
>    archive/archive.h
>
>    DESTINATION ${INCLUDE_INSTALL_DIR}/gluon/player/lib/archive
>    COMPONENT Devel
> )
>
> install(FILES
>    models/commentitemsmodel.h
>    models/gameitemsmodel.h
>    models/highscoresmodel.h
>    DESTINATION ${INCLUDE_INSTALL_DIR}/gluon/player/lib/models
>    COMPONENT Devel
> )
>
> I wonder whether it could be done smarter. In the example above, there
> are subfolders like archive, models. It could also contain 5-10
> subfolders (even more) and we install the headers this way: one
> separate install section for each subfolder even if we explicitely
> write the subfolders all the time, like "archive/archive.h",
> "models/commentitemsmodel.h", et cetera.

May be you could put a CMakeLists.txt in each subdir
such that:

in the parent folder you could:

set(SUBDIRS "archive;models;whatever")
foreach(SD IN LISTS SUBDIRS)
  add_subdirectory(${SD})
endforeach()

then inside each directory:

get_filename_component(CDIR ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(filelist "commentitemsmodel.h gameitemsmodel.h highscoresmodel.h")
install(FILES ${filelist}
          DESTINATION ${INCLUDE_INSTALL_DIR}/gluon/player/lib/${CDIR}
          COMPONENT Devel)


The latest CMakeLists.txt (the one in the subdir) is almost always the
same and could
be generated with a minimal script.

Not sure whether if it's better than your current solution.
May be it's a little less painless to write.

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


More information about the CMake mailing list