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

include header file fail #5517

Open
JoJoBizarreAdventure opened this issue Mar 28, 2024 · 2 comments
Open

include header file fail #5517

JoJoBizarreAdventure opened this issue Mar 28, 2024 · 2 comments

Comments

@JoJoBizarreAdventure
Copy link

I import assimp v5.3.1 as a submodule. Then use similar cmake as below:

add_subdirectory(assimp)
function(link_assimp target_name)
    target_link_libraries(${target_name} PRIVATE assimp)
endfunction()

When I use link_assimp later, something wrong happend.
image

As the image showed, header file including work normally in source file but fail in the header.

I have tried to use forward declaration to avoid this, but it's hard to deal with enum type like aiTextureType.

I test all these things under win11 with visual studio toolchain in Clion.

I wonder if there is some smart tricks for fixing. Please give me some advice.

@JoJoBizarreAdventure
Copy link
Author

The situation is just similar to this one - #4827

But the include directory should be already linked with target_link_libraries. So confusing...

@JoJoBizarreAdventure
Copy link
Author

JoJoBizarreAdventure commented Mar 28, 2024

Oh! I got an answer. Update the previous code like this will work:

add_library(assimp_header INTERFACE)
target_include_directories(assimp_header
        INTERFACE
        ${CMAKE_CURRENT_SOURCE_DIR}/assimp/include)
target_include_directories(assimp_header
        INTERFACE
        ${CMAKE_CURRENT_BINARY_DIR}/assimp/include)
function(link_assimp target_name)
    target_link_libraries(${target_name} PRIVATE assimp)
    target_link_libraries(${target_name} INTERFACE assimp_header)
endfunction()

Adding INTERFACE library will help with including. I check few repo for this ( like eigen,), all of these having similar design.

I wonder maybe assimp need one either.

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

1 participant