<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>I have an external CMake project that gets exported on install.
The root project uses it as a package. The external project must
be installed prior being used as a package.<br>
</p>
<p>I can solve this problem by using `ExternalProject` for both
projects and declare their dependency. My setup is different,
though, as the root project depends on an external project. Since
I am including the external project without it having installed on
system I am not sure if it is correct to use the package as
downstream or whether upstream should be applied instead.<br>
</p>
<p><br>
Consider the following project structure:<br>
<br>
my_test<br>
├── cmake<br>
├── extern<br>
│ └── mylibrary<br>
│ ├── cmake<br>
│ ├── include<br>
│ │ └── my_library<br>
│ └── src<br>
├── include<br>
│ └── my_test<br>
└── src<br>
<br>
`mylibrary` is a standalone project with `export` on install to
use its library as package. <br>
<br>
`my_test` (root) is another project that depends on `mylibrary`.<br>
<br>
CMakeLists.txt:<br>
```<br>
# add dependencies<br>
add_subdirectory( extern )<br>
add_subdirectory( src )<br>
```<br>
<br>
extern/CMakeLists.txt:<br>
```<br>
ExternalProject_Add(mylibrary<br>
CMAKE_ARGS <br>
-D CMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}<br>
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mylibrary"<br>
)<br>
```<br>
<br>
src/CMakeLists.txt:<br>
```c <br>
list( APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}" )<br>
<br>
find_package( my_library REQUIRED )<br>
<br>
#=============================<br>
# Define targets<br>
#=============================<br>
add_executable( MyTestProject test.cpp )<br>
add_dependencies(MyTestProject my_library-exportname)<br>
target_link_libraries( MyTestProject PUBLIC my_library-exportname)<br>
```<br>
<br>
I added `add_dependencies` to have `my_library` be installed prior
to building `my_test`. However, build fails even before that since
I have `find_package()` in the same CMake txt file. <br>
<br>
<b>How can I setup my install as dependency for a package?</b><br>
</p>
</body>
</html>