Please consider below CMakeLists.txt.
I am adding an external project if I am unable to find FOO; mylib1 and mylib2 depends on FOO.
This works if I am doing make, it sets up FOO if not found and proceeds towards mylib1 and mylib2.
However if I run make -j4 it does not quite work, as more workers are available it rushes to do mylibX while foo is being setup - end result is mylibX builds fails. Which brings me to my question:
In cmake, what is the idiomatic way to conditionally include a ExternalProject_Add() call?
cmake_minimum_required(VERSION 3.10)
project(myAweSomeLibs VERSION 1.0)
find_library(FOO
NAMES foo
)
if (FOO)
message("Found FOO")
else()
message("Foo not found. Adding external project")
include(ExternalProject)
ExternalProject_Add(foobar
GIT_REPOSITORY git@github.com:FooCo/FooBar.git
GIT_TAG origin/release/1.2.3
)
endif()
add_subdirectory(mylib1)
add_subdirectory(mylib2)