Reputation: 1642
I have
ExternalProjectAdd(googletest ......)
...
add_library(gtest_main UNKNOWN IMPORTED)
set_target_properties(gtest_main PROPERTIES
"IMPORTED_LOCATION" ${binary_dir}/googlemock/gtest/libgtest_main.a
)
...
add_executable(sometest somefile.cpp)
target_link_library(sometest gtest_main)
add_dependencies(sometest googletest)
But evidently stating the dependency of the executable sometest
on googletest
does not actually require the ExternalProject_Add
's build command to be invoked prior to the build command for sometest
.
If I run ninja
then it complains that it can't find libgtest_main.a
. But if you call ninja googletest && ninja sometest
it works just fine.
So, how do you tell cmake
that sometest
depends on googletest
's build command being invoked?
Upvotes: 8
Views: 2571
Reputation: 1103
As mentioned in the comments, the issue is related to Ninja generator and its mechanism of scanning dependencies (more details).
For solve the issue need to add additional Cmake option BUILD_BYPRODUCTS with expected path to library that will be compiled:
ExternalProject_add(
...
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/googlemock/gtest/libgtest_main.a
)
This should help to get rid of error like this:
ninja: error: 'gtest/libgtest_main.a', needed by 'sometest.so', missing and no known rule to make it
I understand that answer is quite late, but hope that it will help someone safe few hours.
Upvotes: 4