How can I add external projects in CMake when the project's repo isn't the root of the library I want to use, but in fact contains two directories which are each root directories of repos that I want to use in my project?
I'm working to set up a framework CMake project that uses Google Test and Mock for testing, however when I try to download the google test repo (https://github.com/google/googletest) with ExternalProject_Add
, it complains on build that it can't find the source for the project. Well, that's because Google have merged googletest and googlemock into a single project, except it's now two projects.
Some of the repo's file structure:
googletest-master/
├──[...no CMakeFiles.txt exists here...]
├──googletest/
│ ├──src/
│ └──CMakeFiles.txt
└──googlemock/
├──src/
└──CMakeFiles.txt
When I do the following...
ExternalProject_Add(
gtest
GIT_REPOSITORY https://github.com/google/googletest.git
TIMEOUT 10
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
PREFIX "googletest-master"
)
...it downloads the actual repo to googletest-master/src/gtest
because I'm prefixing the repo with "googletest-master" to keep it out of my main source code, and it assumes that I'm downloading a project that is only source and that source is in the root directory.
So I'd like to accomplish two things:
You need single download step, but two build steps. Different ExternalProject_add
command calls cannot share steps, but you can arrange all these steps into different calls with appropriate dependencies between them:
# Single download(git clone)
ExternalProject_Add(
googletest-master
DOWNLOAD_DIR "googletest-master/src" # The only dir option which is required
GIT_REPOSITORY https://github.com/google/googletest.git
TIMEOUT 10
LOG_DOWNLOAD ON
# Disable all other steps
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
# Build gtest from existing sources
ExternalProject_Add(
gtest
DOWNLOAD_COMMAND "" # No download required
SOURCE_DIR "googletest-master/src/googletest" # Use specific source dir
PREFIX "googletest-master" # But use prefix for compute other dirs
INSTALL_COMMAND ""
LOG_CONFIGURE ON
LOG_BUILD ON
)
# gtest should be build after being downloaded
add_dependencies(gtest googletest-master)
# Build gmock from existing sources
ExternalProject_Add(
gmock
DOWNLOAD_COMMAND "" # No download required
SOURCE_DIR "googletest-master/src/googlemock" # Use specific source dir
PREFIX "googletest-master" # But use prefix for compute other dirs
INSTALL_COMMAND ""
LOG_CONFIGURE ON
LOG_BUILD ON
)
# gmock should be build after being downloaded
add_dependencies(gmock googletest-master)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With