Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake FetchContent #130

Open
myzinsky opened this issue Oct 7, 2024 · 5 comments
Open

CMake FetchContent #130

myzinsky opened this issue Oct 7, 2024 · 5 comments

Comments

@myzinsky
Copy link

myzinsky commented Oct 7, 2024

Im using the lib via FetchContent in my project.

message(STATUS "Fetching libad9361-iio from github")
FetchContent_Declare(
    libad9361-iio
    GIT_REPOSITORY https://github.com/analogdevicesinc/libad9361-iio
    GIT_TAG main
)
FetchContent_MakeAvailable(libad9361-iio)

However, there is a naming clash with another library that also has a target uninstall:

[cmake] CMake Error at out/build/Debug/_deps/libad9361-iio-src/CMakeLists.txt:217 (add_custom_target):
[cmake]   add_custom_target cannot create target "uninstall" because another target
[cmake]   with the same name already exists.  The existing target is a custom target
[cmake]   created in source directory
[cmake]   "/Users/myzinsky/Programming/qluto4/out/build/Debug/_deps/sdl2-src".  See
[cmake]   documentation for policy CMP0002 for more details.

One workaround would be to change the cmake a bit, in this way:

if(NOT TARGET uninstall) 

endif()

Any thoughts?

@tfcollins
Copy link
Contributor

My understanding is FetchContent is normally used to include things like header only projects or general source you want to use. Do you not want to simply link against libiio? What is your end goal here?

@myzinsky
Copy link
Author

myzinsky commented Oct 7, 2024

I will setup a project, where cmake will automatically download all dependencies. iio and ad9361 are just 2 of 10 dependencies that I have.

@tfcollins
Copy link
Contributor

Are you building all the dependencies from source (even libiio's)? Or can you use prebuilt binaries? What is the target OS?

@myzinsky
Copy link
Author

myzinsky commented Oct 8, 2024

So it's even the problem when both, iio and this library are combined. It would be already enough to rename the targets to uninstall_iio and uninstall_ad9361-iio.

I want to have a full independence from pebuild libraries. Such that my program can be just build everywhere.

@myzinsky
Copy link
Author

myzinsky commented Oct 8, 2024

Seems that this would be a solution that works around this:

cmake_minimum_required(VERSION 3.30)
project(pluto17)
include(FetchContent)
include(ExternalProject)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

ExternalProject_Add(
    libiio
    GIT_REPOSITORY https://github.com/analogdevicesinc/libiio
    GIT_TAG v0.26
    INSTALL_COMMAND   ""
)

ExternalProject_Add(
    libad9361-iio
    GIT_REPOSITORY https://github.com/analogdevicesinc/libad9361-iio
    GIT_TAG v0.3
    INSTALL_COMMAND   ""
    CMAKE_ARGS
        -DLIBIIO_INCLUDEDIR=${CMAKE_BINARY_DIR}/libiio-prefix/src/libiio/
        -DLIBIIO_LIBRARIES=${CMAKE_BINARY_DIR}/libiio-prefix/src/libiio-build/iio.framework/
)

add_executable(pluto17
    src/main.cpp
)

add_dependencies(pluto17 libiio libad9361-iio)

target_include_directories(pluto17
    PRIVATE ${CMAKE_BINARY_DIR}/libiio-prefix/src/libiio/
)

target_link_libraries(pluto17 PRIVATE ${CMAKE_DL_LIBS})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants