CMake module for downloading an external project's source at configure time

Related tags

Build Systems cmake
Overview

DownloadProject

Platform Build status
Linux
Mac OSX
Build Status
Windows (VS2015) Build status

This repository contains a generalized implementation for downloading an external project's source at CMake's configure step rather than as part of the main build. The primary advantage of this is that the project's source code can then be included directly in the main CMake build using the add_subdirectory() command, making all of the external project's targets, etc. available without any further effort. The technique is fully explained in the article available at:

https://crascit.com/2015/07/25/cmake-gtest/

An example as described in that article is provided here to demonstrate how to use the DownloadProject module. It uses googletest as the example, downloading and building trivial gtest and gmock test cases to show the technique.

Comments
  • not working in a nested project

    not working in a nested project

    @audiofanatic I've tried to use the download_project function in a child directory of a project and it doesn't download the external project.

    Any tip or hint? thanks!

    opened by edgarriba 8
  • Downloaded projects using ${CMAKE_SOURCE_DIRECTORY} break

    Downloaded projects using ${CMAKE_SOURCE_DIRECTORY} break

    Since projects are downloaded as source, when a project uses ${CMAKE_SOURCE_DIRECTORY} it uses the source directory of the highest level project and disrupts the resulting paths.

    Is this a limitation of this approach, or can this be worked around?

    opened by zfields 6
  • GTest example doesn't work with MSVC 11

    GTest example doesn't work with MSVC 11

    The GTest example actually doesn't work with MSVC 11 (toolset v110) due to VC++ not supporting variadic templates.

    The problem can be fixed by defining GTEST_HAS_TR1_TUPLE to 0 or _VARIADIC_MAX to 10, although the latter is more of a band aid than a solution.

    This is just a heads up for anyone who might want to use this with an old version of MSVC

    opened by tschuchortdev 6
  • How can we disable the install step?

    How can we disable the install step?

    When I used your extension as

    include(DownloadProject)
    download_project(PROJ                googletest
                     GIT_REPOSITORY      https://github.com/google/googletest.git
                     GIT_TAG             master
                     ${UPDATE_DISCONNECTED_IF_AVAILABLE}
    )
    add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
    

    I have the problem that the downloaded project gets installed as well when my project installs can I somehow disable this?

    This is not related to this library but maybe you can help :-)

    opened by gabyx 6
  • Switching revisions redownloads full repository

    Switching revisions redownloads full repository

    We use this awesome script to download our 3rdparty repository containing several gigabytes of pre-buillt thirdparty libraries.

    However, when we add a new prebuild there and consequently update the referenced version in our main repository's cmake, the whole repository is checked out again (Instead of just downloading the diff). This takes hours for our +20 GB repository, especially via VPN.

    Is there a way to achieve just a git pull using DownloadProject or FetchContent?

    opened by PhilLab 5
  • Not working for git repositories with ssh authentication

    Not working for git repositories with ssh authentication

    When I try to use it with a project that requires SSH autentication it is not working. I use the url in the form [email protected]:Crascit/DownloadProject.git but it seems not able to grab the private key. Is it supported?

    opened by limdor 4
  • Remove CMakeCache when configuring.

    Remove CMakeCache when configuring.

    This fixes an issue with CLion that means that the dependencies get built in the wrong directory due to the CMakeCache.txt being copied between the directories. No adverse effect is caused for other generators.

    opened by chrisstaite 4
  • gmake: No rule to make target error with cmake 3.6.3

    gmake: No rule to make target error with cmake 3.6.3

    The UPDATE_DISCONNECTED command is broken in cmake 3.5 and cmake 3.6. Here is the bug report: https://cmake.org/Bug/view.php?id=15904. Currently its use is recommended in your docs:

    https://github.com/Crascit/DownloadProject/blob/master/DownloadProject.cmake#L58

    Please consider removing this advice.

    opened by drizzd 4
  • compile options and static import path

    compile options and static import path

    Hi, very interesting idea and I wanted to get your feedback on a couple ideas.

    The first is an issue with an independent generate + build process. I am getting the following error:

    gtest.lib(gtest-all.cc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in mytest.cpp.obj
    

    My thoughts (not an expert in this area) are the separate execute_process is not pulling in my current CMake options, such as MSVC compile flags. Do you see a convenient way of forwarding these in the DownloadProject.cmake?

    1. I don't want these sources in the same folder as my tests. I've roughly injected a static path for this:
    include(CMakeParseArguments)
    
    set(DOWNLOAD_PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR})
    
    function(download_project)
    ...
        configure_file("${DOWNLOAD_PROJECT_DIR}/DownloadProject.CMakeLists.cmake.in" ${DL_ARGS_PROJ}-download/CMakeLists.txt)
    ...
    endfunction()
    

    Curious about your thoughts. Thanks!

    opened by jacobblock 4
  • Unexpected prefix behavior

    Unexpected prefix behavior

    I would like to have all the external projects under the same directory. A ThirdParty folder placed at the rood of cmake_binary_dir. When using ExternalProject_Add, this can be done locally to each project using [PREFIX dir] or globally as follows:

    # Set default ExternalProject root directory
    set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/ThirdParty)
    

    However when using DownloadProject, this EP_PREFIX has no effect even when forced like this:

    download_project(PROJ                googletest
                     PREFIX "ThirdParty"
                     GIT_REPOSITORY      https://github.com/google/googletest.git
                     GIT_TAG             master
                     ${UPDATE_DISCONNECTED_IF_AVAILABLE}
    )
    

    The project is downloaded at ./ThirdParty/googletest-download indeed, but then CMake crushes since ./ThirdParty/googletest-src is not created.

    -- Build files have been written to: /tmp/DownloadProject/build/ThirdParty/googletest-download
    Scanning dependencies of target googletest-download
    [ 11%] Creating directories for 'googletest-download'
    [ 22%] Performing download step (git clone) for 'googletest-download'
    Cloning into 'googletest-src'...
    Already on 'master'
    Your branch is up-to-date with 'origin/master'.
    [ 33%] No patch step for 'googletest-download'
    [ 44%] Skipping update step for 'googletest-download'
    [ 55%] No configure step for 'googletest-download'
    [ 66%] No build step for 'googletest-download'
    [ 77%] No install step for 'googletest-download'
    [ 88%] No test step for 'googletest-download'
    [100%] Completed 'googletest-download'
    [100%] Built target googletest-download
    CMake Error at CMakeLists.txt:25 (add_subdirectory):
      add_subdirectory given source "ThirdParty/googletest-src" which is not an
      existing directory.
    

    What am I missing?

    opened by massich 3
  • Project not being built after download

    Project not being built after download

    I'm trying to automate the download and build of mariadb-connector-c and added this to he CMakeLists.txt where I define my tests (not the one at the root of my project):

    download_project(PROJ               mariadb-connector-c
                     GIT_REPOSITORY     https://github.com/MariaDB/mariadb-connector-c
                     GIT_TAG            master
                     ${UPDATE_DISCONNECTED_IF_AVAILABLE}
    )
    add_subdirectory(${mariadb-connector-c_SOURCE_DIR} ${mariadb-connector-c_BINARY_DIR})
    

    While the source code is downloaded, the result of running CMake on the connector is stored in the -download folder and the product is not built or configured, I need to run cmake manually again.

    Is there a way to go around this?

    opened by ruipacheco 2
  • Add mention of CMake 3.11 FetchContent

    Add mention of CMake 3.11 FetchContent

    A similar tool was just added to CMake 3.11: the FetchContent module, which downloads content at configure time. I would recommend adding a mention of this module to the README just in case a user is okay with requiring CMake 3.11+.

    opened by henryiii 9
Owner
Crascit Pty Ltd
Crascit Pty Ltd
cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Matthias Kleemann 163 Dec 5, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 82 Nov 30, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 74 Dec 26, 2022
[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

julp 29 Nov 2, 2022
A minimal CMake template for Qt 5 & 6 projects

Minimal CMake Template for Qt 6 Projects This project is updated for Qt 6. Visit qt5 branch if you are looking for the Qt 5 template. This is a minima

Vincent Lee 180 Sep 21, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.6k Jan 9, 2023
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

Cristian Adam 65 Dec 6, 2022
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 395 Dec 24, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 39 Oct 2, 2022
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

IXM 107 Sep 1, 2022
curl cmake module libcurl build with msvc x86

curl-msvc Infomation curl cmake module libcurl build with MSVC10.0 arch (x86 | i386) source from https://github.com/curl/curl tags: curl-7_79_1 Usage

Jason Payne 0 May 16, 2022
CMake module to speed up builds.

cotire Cotire (compile time reducer) is a CMake module that speeds up the build process of CMake based build systems by fully automating techniques as

Sascha Kratky 1.3k Dec 26, 2022
CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp

FindIDL CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp. Introduction Requirements Usage find_package() add_idl() ad

Apriorit Inc. 17 Dec 7, 2022
CMake module for building Windows Installer packages with WiX toolset

FindWiX CMake module for building Windows Installer packages with WiX toolset Introduction Requirements Usage find_package() wix_add_project() WiX com

Apriorit Inc. 11 Aug 5, 2022
CMake find module for Intel Threading Building Blocks

FindTBB Module FindTBB is a CMake find package module for Intel® Threading Building Blocks (TBB). Usage The signature of the TBB find module in CMake

Justus Calvin 84 Dec 3, 2022
CMake module for Mathematica.

FindMathematica FindMathematica is a CMake module that tries to find a Wolfram Language installation and provides CMake functions for its C/C++ interf

Sascha Kratky 51 Dec 14, 2022
Source code formatter for cmake listfiles.

cmake lang The cmakelang project provides Quality Assurance (QA) tools for cmake: cmake-annotate can generate pretty HTML from your listfiles cmake-fo

null 760 Dec 31, 2022
A template for projects using both libPeConv and MS Detours

A CMake template for projects using MS Detours along with libPeConv.

hasherezade 14 Dec 16, 2022
CMake project for BL602 RISC-V processor

bl602_cmake_base CMake project for BL602 RISC-V processor How to build NOTE : This project uses a pre-compiled version of the Buffalo SDK (bl_iot_sdk)

null 9 Jan 6, 2022