<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection">
<div dir="auto">ExternalProject does its work at build time, so too late for find_package which is executed at config time.
<div dir="auto">Have a look at module <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a> which does its work before config time.</div>
</div>
</div>
<div name="messageReplySection">Le 19 nov. 2019 à 16:13 +0100, hex <hex7c3@gmail.com>, a écrit :<br />
<blockquote type="cite" class="spark_quote" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<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>
--<br />
<br />
Powered by kitware.com/cmake<br />
<br />
Kitware offers various services to support the CMake community. For more information on each offering, please visit https://cmake.org/services<br />
<br />
Visit other Kitware open-source projects at https://www.kitware.com/platforms<br />
<br />
Follow this link to subscribe/unsubscribe:<br />
https://cmake.org/mailman/listinfo/cmake<br />
<br />
This mailing list is deprecated in favor of https://discourse.cmake.org<br /></blockquote>
</div>
</body>
</html>