I can’t find a solution to run a find_package() between 2 externalProject_add() during the “build time”. Indeed, Project2 needs Project1 both being compiled by externalProject.
But since Project2 doesn’t use cmake but nmake and make, I need to specify the path of Project1 in the arguments of nmake.
To be precise, Project2 is gdal.
You can use an internal API to do some replacement:
set(var "<BINARY_DIR>/some/sub/path")
_ep_replace_location_tags(proj1 var)
# var now has `<BINARY_DIR>` replaced with `proj1`'s value.
Though I would recommend instead using <INSTALL_DIR> which all projects generally share. This would allow you to do something like PROJ1_LIB=<INSTALL_DIR>/lib/proj1.lib.
I didn’t understand much…
With your method, I still couldn’t use find_package() during the build, could I?
I know the location of the libraries, but I’d rather use the ${PROJ_LIBRARIES} variable of the find_package
Yes, but you can use <INSTALL_DIR> to help find_package(proj4) find what it needs. For example, something like passing -DCMAKE_INSTALL_PREFIX:STRING=<INSTALL_DIR>.
My problem is that I can’t use the find_package at “configure” time, because an external project is not yet installed and compiled. So I have to use a find package only during the project build, after proj1 has been installed.
Ok, looking closer, it looks like you’re using per-project INSTALL_DIR settings. Is there a reason for that? I think using a single install prefix for all projects would make this a lot easier.
If not, you can use _ep_replace_location_tags to expand variables for other projects to build up the information you need.
I already have the solution without using a find_package between 2 ExternalProject_add, but this is verbose. I don’t want to make a mixed install directory either. I have one install directory per external project.
My initial question is how to use a find_package during the build between 2 external_project, with a find_package that refers to the first project.
Sorry about that. I don’t always go back and reread threads and I guess I lost track of what was originally being asked here.
I don’t know of any way to do what you’re asking easily other than possibly adding a CMake project in between that dumps the information out in a way that the second project slurps up during its build. Maybe you can dump out a response file (I’d use xargs, but I don’t know what Windows has like that)?
Since proj2 is not a CMake project, it can’t call find_package(). But you want the results of a find_package() call to give to it. You can’t call find_package() until build time because the thing you want it to find isn’t set up until build time. Therefore, proj2 has to either be a CMake project or you have to insert one somehow to be able to call find_package() at that point in the build stage.
Probably you will need to either insert a third project between them that writes out something that proj2 can read, or else you could try to modify proj2 to create its own local CMake project to do the same. Neither is particularly clean, but that’s hard to avoid when mixing build systems like this.
I tried to do this but without success.
I used an externalProject_add with just SOURCE_DIR on a local directory with a cmakelist.txt, and in this CMakelist.txt, I wanted to make an externalProject_add on proj2. But I got some strange error messages about proj2 generator problems
I have no other method than to use externalProject_Add to launch a cmakelist during the build time