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

provide example demonstrating CONAN_INCLUDE_DIRS_XXX #82

Open
paigeadelethompson opened this issue Mar 16, 2023 · 4 comments
Open

provide example demonstrating CONAN_INCLUDE_DIRS_XXX #82

paigeadelethompson opened this issue Mar 16, 2023 · 4 comments

Comments

@paigeadelethompson
Copy link

I'm sorta noticing that the CONAN_INCLUDE_DIRS_XXX isn't substantiated by the CMakeDeps CMakeToolchain generators,

❯ ls
BZip2-Target-release.cmake            ZLIB-release-armv8-data.cmake         conanbuild.sh                         libxcrypt-Target-release.cmake        pcre-Target-release.cmake
BZip2-release-armv8-data.cmake        ZLIBConfig.cmake                      conanbuildenv-release-armv8.sh        libxcrypt-config-version.cmake        pcre-config-version.cmake
BZip2Config.cmake                     ZLIBConfigVersion.cmake               conanrun.sh                           libxcrypt-config.cmake                pcre-config.cmake
BZip2ConfigVersion.cmake              ZLIBTargets.cmake                     conanrunenv-release-armv8.sh          libxcrypt-release-armv8-data.cmake    pcre-release-armv8-data.cmake
BZip2Targets.cmake                    argon2-Target-release.cmake           deactivate_conanbuild.sh              libxcryptTargets.cmake                pcreTargets.cmake
CMakeCache.txt                        argon2-config-version.cmake           deactivate_conanrun.sh                module-BZip2-Target-release.cmake     utf8cpp-Target-release.cmake
CMakeFiles                            argon2-config.cmake                   http_parser-Target-release.cmake      module-BZip2-release-armv8-data.cmake utf8cpp-config-version.cmake
CMakePresets.json                     argon2-release-armv8-data.cmake       http_parser-config-version.cmake      module-BZip2Targets.cmake             utf8cpp-config.cmake
FindBZip2.cmake                       argon2Targets.cmake                   http_parser-config.cmake              module-ZLIB-Target-release.cmake      utf8cpp-release-armv8-data.cmake
FindZLIB.cmake                        cmakedeps_macros.cmake                http_parser-release-armv8-data.cmake  module-ZLIB-release-armv8-data.cmake  utf8cppTargets.cmake
ZLIB-Target-release.cmake             conan_toolchain.cmake                 http_parserTargets.cmake              module-ZLIBTargets.cmake
❯ grep -r CONAN_INCLUDE_DIRS
~/inspircd/build master* ⇣⇡                                                                                                                                                                                    12:33:47 PM
❯

I had to go rooting around to find the INCLUDE DIR path names look like

include_directories(
  include/
  ${libxcrypt_INCLUDE_DIRS_RELEASE}
)

But, it don't work. Is it broke? Why'd they even change this it looks like Conan 1.x did what it was supposed to do?

@paigeadelethompson
Copy link
Author

paigeadelethompson commented Mar 16, 2023

Oh hey I think I figured this out now, I was on the right path, you just have to make sure to require it for those variables to work:

find_package(libxcrypt REQUIRED)

include_directories(
  include/
  ${argon2_INCLUDE_DIR}
)

and then I could see it was correct and adding the -I path/ in the build output from cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake && cmake --build . --parallel 8

To be honest I don't even know if thats the way you're supposed to do it because that seems counter intuitive? I don't know, I just haven't had much luck finding the right answers maybe..

@memsharded
Copy link
Member

Hi @paigeadelethompson

Thanks for your suggestion.
The thing is that such variables are internal implementation detail of the CMakeDeps generator. They shouldn't be used directly, also because modern CMake good practices discourage that approach.
The recommended approach is to link with the target, and such target will bring everything in it: the include-dirs, the lib-dirs, the libs, the necessary flags and definitions, etc. So mostly:

find_package(mydep REQUIRED)

target_link_libraries(mylib_or_app mydep::mydep)

The name of the target is by default the name of the package::package, but it can vary for open source third parties with different conventions. They will typically be printed on screen when find_package() finds the package.

@paigeadelethompson
Copy link
Author

Ah interesting, yeah I'm not really sure then I thought maybe I saw someone say that it had something to do with trying to use add_subdirectory() caused the includes to not get injected into the executor but I really don't know I must've read through a dozen pages trying to get it to work and instead I settled for the counter intuitive way of doing it for now, and it works:

https://github.com/paigeadelethompson/clandestine/blob/master/CMakeLists.txt

maybe if you wanna take a look at that and see if you can figure out why I had to do it that way feel free but for now everything seems to be working so I can't complain other than

https://github.com/paigeadelethompson/clandestine/blob/master/src/modules/extra/CMakeLists.txt#L1

some of the pkg_FOUND names are really hard to guess. Stuff appears to be linking correctly but I'm not sure if I have to also install(pkgName) or if its statically linked or whats going on (haven't had much of a chance to test it just kinda got it together and building for now.)

I put an action into workflows for building this if you wanna take a look at the build log in github instead of building yourself:

https://github.com/paigeadelethompson/clandestine/actions/runs/4449257228/jobs/7813179909

@paigeadelethompson
Copy link
Author

yeah I couldn't quite figure out how to get XCode / CMake / Conan working together right either. XCode builds my project ok, but it's not picking up any of my Conan dependencies for some reason. I actually switched to using target_include_directories for some things, I've been working in a different branch:

https://github.com/paigeadelethompson/clandestine/blob/services/ircd/src/CMakeLists.txt#L44

I wonder though I'm still using include_directories in places where I have lots of targets like here: https://github.com/paigeadelethompson/clandestine/blob/services/ircd/src/modules/CMakeLists.txt#L3

But I wonder now if maybe if include_directories is breaking Conan and causing things like target_link_libraries to not work correctly:

https://github.com/paigeadelethompson/clandestine/blob/services/ircd/src/modules/extra/CMakeLists.txt#L553

In XCode what I'm noticing is that when I try to build, if(sqlite3_FOUND) will evaluate to true but target_link_libraries(m_sqlite3 clandestine SQLite::SQLite3) never links because when it XCode tries to link there are unresolved symbol errors. However building with CMake from command line this works fine. So I'll check when I get a chance later today, I imagine there's probably something somewhere that I've overlooked, but at least its coming along some :)

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