Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell CMAKE to download some necessary header files (more precisely GLM math library) WITHOUT TRYING TO COMPILE THEM?

I am setting up a CMAKE project that uses a lot of ExternalProjects. To build one of them (CEGUI), I need to download the GLM (OpenGL Math Library). This Library is include only library, which means that you mustn't compile it. There are some test that can be compiled but there is no need for them in my project (moreover, one of them do not compile properly and breaks the compiling chain).

What I would like, is to find a way to tell CMAKE to only download the project (GIT update etc) like it does normally using the ExternalProject_add() function, but without trying to compile it (which produces a FATAL ERROR), and install the INCLUDE files (which are the library indeed).

Is there a download header files and install them functionnality in CMAKE? Does anyone already have this problem with GLM header-library?

like image 227
Danduk82 Avatar asked Jan 19 '14 21:01

Danduk82


1 Answers

You can avoid a configure and build step in ExternalProject_Add by setting CONFIGURE_COMMAND and BUILD_COMMAND as empty strings.

As for installing - I generally don't bother. I like to keep all third party sources inside my own build tree, and just refer to these in my own project. However, you could probably make the install step in this case something like cmake -E copy_directory ....

So the full command could be:

include(ExternalProject)
ExternalProject_Add(
    glm
    PREFIX ${CMAKE_BINARY_DIR}/glm
    GIT_REPOSITORY https://github.com/g-truc/glm.git
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
                    <SOURCE_DIR>/glm ${CMAKE_BINARY_DIR}/installed/glm
    LOG_DOWNLOAD ON
    LOG_INSTALL ON
    )

If you wanted to avoid the install step too, then also just set it to an empty string. Then to get the GLM include directory (to be used in subsequent target_include_directories or include_directories calls), just do e.g:

include(ExternalProject)
ExternalProject_Add(
    glm
    PREFIX ${CMAKE_BINARY_DIR}/glm
    GIT_REPOSITORY https://github.com/g-truc/glm.git
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    LOG_DOWNLOAD ON
    )
ExternalProject_Get_Property(glm source_dir)
set(GlmIncludeDir ${source_dir}/glm)

...

target_include_directories(MyTarget PRIVATE ${GlmIncludeDir})
like image 188
Fraser Avatar answered Oct 09 '22 02:10

Fraser