Dependencies of an external project

classic Classic list List threaded Threaded
2 messages Options
Hex
Reply | Threaded
Open this post in threaded view
|

Dependencies of an external project

Hex

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.

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.


Consider the following project structure:

my_test
├── cmake
├── extern
│   └── mylibrary
│       ├── cmake
│       ├── include
│       │   └── my_library
│       └── src
├── include
│   └── my_test
└── src

`mylibrary` is a standalone project with `export` on install to use its library as package.

`my_test` (root) is another project that depends on `mylibrary`.

CMakeLists.txt:
```
# add dependencies
add_subdirectory( extern )
add_subdirectory( src )
```

extern/CMakeLists.txt:
```
ExternalProject_Add(mylibrary
    CMAKE_ARGS
        -D CMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
    SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mylibrary"
)
```

src/CMakeLists.txt:
```c
list( APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}" )

find_package( my_library REQUIRED )

#=============================
# Define targets
#=============================
add_executable( MyTestProject test.cpp )
add_dependencies(MyTestProject my_library-exportname)
target_link_libraries( MyTestProject PUBLIC my_library-exportname)
```

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. 

How can I setup my install as dependency for a package?


--

Powered by kitware.com/cmake

Kitware offers various services to support the CMake community. For more information on each offering, please visit https://cmake.org/services

Visit other Kitware open-source projects at https://www.kitware.com/platforms

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

This mailing list is deprecated in favor of https://discourse.cmake.org
Reply | Threaded
Open this post in threaded view
|

Re: Dependencies of an external project

Marc CHEVRIER
ExternalProject does its work at build time, so too late for find_package which is executed at config time.
Have a look at module FetchContent which does its work before config time.
Le 19 nov. 2019 à 16:13 +0100, hex <[hidden email]>, a écrit :

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.

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.


Consider the following project structure:

my_test
├── cmake
├── extern
│ └── mylibrary
│ ├── cmake
│ ├── include
│ │ └── my_library
│ └── src
├── include
│ └── my_test
└── src

`mylibrary` is a standalone project with `export` on install to use its library as package.

`my_test` (root) is another project that depends on `mylibrary`.

CMakeLists.txt:
```
# add dependencies
add_subdirectory( extern )
add_subdirectory( src )
```

extern/CMakeLists.txt:
```
ExternalProject_Add(mylibrary
CMAKE_ARGS
-D CMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mylibrary"
)
```

src/CMakeLists.txt:
```c
list( APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}" )

find_package( my_library REQUIRED )

#=============================
# Define targets
#=============================
add_executable( MyTestProject test.cpp )
add_dependencies(MyTestProject my_library-exportname)
target_link_libraries( MyTestProject PUBLIC my_library-exportname)
```

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.

How can I setup my install as dependency for a package?

--

Powered by kitware.com/cmake

Kitware offers various services to support the CMake community. For more information on each offering, please visit https://cmake.org/services

Visit other Kitware open-source projects at https://www.kitware.com/platforms

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

This mailing list is deprecated in favor of https://discourse.cmake.org

--

Powered by kitware.com/cmake

Kitware offers various services to support the CMake community. For more information on each offering, please visit https://cmake.org/services

Visit other Kitware open-source projects at https://www.kitware.com/platforms

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

This mailing list is deprecated in favor of https://discourse.cmake.org