CMake ExternalProject_Add Git
Asked Answered
A

3

7

I have a git-bare-repository on my desktop and I would like to clone it with CMake. My repository has this path C:\Users\demoUser\Desktop\learnGIT\prog. My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)
project(Demo)
include(ExternalProject)

ExternalProject_Add(demo
  GIT_REPOSITORY C:/Users/demoUser/Desktop/learnGIT/prog
  GIT_TAG master
  UPDATE_COMMAND ""
  INSTALL_COMMAND ""
)

but in the generated folder prog-build is just wast. The generated folder structure doesn't include any of my files from the repository.

Does somebody has an idea?

Amalburga answered 3/2, 2015 at 19:22 Comment(1)
please post any error messages cmake/make/VS gives you. which exact cmake version are you using? it runs fine on cmake 3.1 on my ubuntu14 where i use exactly your code (but my bare repo and branch).Alkali
R
6
  1. You have to have a target in your project that depends on external project

    add_dependencies(TargetName ExternalProjectName)
    
  2. The git clone happens on TargetName build (not on CMake reload)

Rubious answered 18/10, 2017 at 7:40 Comment(0)
W
0

you have to tell cmake that it needs "demo" to build your target. In this way you force cmake to download the external project "demo" before compiling.

for example

set(SRC ${PROJECT_SOURCE_DIR}/src/main.cpp 
    ${PROJECT_SOURCE_DIR}/src/file1.cpp)  
    add_executable(Demobin ${SRC})  
    add_dependencies(Demobin demo)
Weltschmerz answered 21/7, 2015 at 16:10 Comment(0)
R
0

You'll find a complete example in this ANSWER.


When you add external projects (via git) it's sometimes important to have these dependent projects fetched (and build) before the building of the main part of your project starts.

You can achieve this by adding the option STEP_TARGETS build to your ExternalProject_Add section. See the ANSWER.

Recruitment answered 8/11, 2019 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.