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

坚强是说给别人听的谎言 提交于 2020-01-24 03:20:07

问题


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?


回答1:


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})


来源:https://stackoverflow.com/questions/21223163/how-to-tell-cmake-to-download-some-necessary-header-files-more-precisely-glm-ma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!