CMake ExternalProject_Add can be used without overhead
external project dependencies does add some extra time each time you run make. https://github.com/jgaa/restc-cpp/commit/261679210a2d26731bf18458562ebd553711947f#diff-f1f2ba7e3d111c581a8491b50429ad82R5
Here I made the minimal possible cmake config to be easier to understand the code. While working with cmake external projects I've found one trick to improve the cmake reload and build speed.
Instead of making the project dependent on external project thus building the external project on each project build
add_dependencies(${PROJECT_NAME} externalRestcCpp)
you can create a virtual target and add all external project dependencies on it
add_custom_target(externalAll)
ExternalProject_Add(externalRestcCpp
PREFIX "${EXTERNAL_PROJECTS_PREFIX}"
GIT_REPOSITORY "https://github.com/jgaa/restc-cpp.git"
GIT_TAG "master"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_INSTALL_PREFIX}
)
add_dependencies(externalAll externalRestcCpp)
Now the target ${PROJECT_NAME} is standalone, the build is fast and library linking still works. When you wan to (re)build all external projects, you build the externalAll target.
I have to read up on this part of cmake and get a better understanding on how it works. There are some things that don't work the way I expect them to, when I use external projects.
The main reason I use external projects is that they do not pollute my project. They are compiled in a separate environment and I just include and link from the installed directory.
They are a new discovery for me, I don't know how they work on all platforms and use cases.
I like the way they work in the project now, except for the extra compile-time for each build. What I want to understand better is how this works in larger projects, where rests-cpp is just a small component, and where other components may have the same dependencies. Also, I want to see if this can be a solution for situations where some dependencies may be med by a Linux distribution (like boost and openssl) with a fall-back to building those libraries if they cannot be found (typically Windows and macOS). I'm on the road today and tomorrow, so I can't start on this right away.
Another trick: Trevent external projects build on install (and all) target build
cmake --build . --target install
add to all external projects
set_target_properties(externalFooBar PROPERTIES EXCLUDE_FROM_ALL TRUE)