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

Including both glog and gflags as cmake subdirectories #560

Closed
growly opened this issue Jun 22, 2020 · 8 comments
Closed

Including both glog and gflags as cmake subdirectories #560

growly opened this issue Jun 22, 2020 · 8 comments
Labels

Comments

@growly
Copy link

growly commented Jun 22, 2020

I haven't found a definitive answer so I'm asking here: does glog support being included as subdirectory in a subsuming cmake project, next to gflags? I'd like my CMakeLists.txt to be as simple as:

add_subdirectory(gflags)
add_subdirectory(glog)

but no dice (find_package fails). I've tried playing with the WITH_GFLAGS, HAVE_LIB_GFLAGS, gflags_FOUND, gflags_NAMESPACE, gflags_INSTALL, etc, variables to trick glog into finding the right installation. @Mizux mentioned that this works when glog is an ExternalProject in #198 - is that the only known/blessed way?

Thanks!

@growly
Copy link
Author

growly commented Jun 22, 2020

I just found @sergiud's comment in #251 that suggests again that only ExternalProject is supported, but that was in 2017. Is that still the case?

@growly
Copy link
Author

growly commented Jun 23, 2020

Ok, if gflags_DIR is set correctly then I get the same error as in #381 regardless of whether I use ExternalProject_Add or add_subdirectory. Based on @sergiud's comments in #381 this is a gflags problem.

So is there any known workaround for getting glog and gflags to co-exist in-tree?

edit: this bug in gflags is still waiting gflags/gflags#279

@sergiud
Copy link
Collaborator

sergiud commented Jun 23, 2020

Unfortunately, I don't see any way to work around this gflags issue in glog.

@Mizux
Copy link
Contributor

Mizux commented Jun 23, 2020

an other way is to hack locally (i.e. by applying a git patch) to your dependency (glog here) so before glog perform a find_package(gflag) you add a check if gflag is present:

so you can modify

glog/CMakeLists.txt

Lines 62 to 69 in 0a2e593

if (WITH_GFLAGS)
find_package (gflags 2.2.0)
if (gflags_FOUND)
set (HAVE_LIB_GFLAGS 1)
determine_gflags_namespace (gflags_NAMESPACE)
endif (gflags_FOUND)
endif (WITH_GFLAGS)

into something like:

if (WITH_GFLAGS)
  if(NOT TARGET gflag::gflag)
    find_package (gflags 2.2.0)

    if (gflags_FOUND)
      set (HAVE_LIB_GFLAGS 1)
      determine_gflags_namespace (gflags_NAMESPACE)
    endif (gflags_FOUND)
  else()
  set(gflags_NAMESPACE gflags) 
  endif()
endif (WITH_GFLAGS)

note: not tested, and blind supposition of the purpose of determine_gflags_namespace(...)

note: In CMake having find_package(Foo) working seamlessly when using add_subdirectory, ExternalProject or FetchContent is still an open issue.
see: https://gitlab.kitware.com/cmake/cmake/-/issues/17735

I would say CMake has always been targeted to unix system/distro way where you install your deps first then you 'find_package()' them so having super build/monolithic project is more or less outside of the kitware scope IMHO
Still I would be happy to see some Kitware/Modern CMake recommendation/good practice to make a library "super build" compatible (for ascendants and descendants deps).

@growly
Copy link
Author

growly commented Jun 24, 2020

thanks!

@eAzure
Copy link

eAzure commented Feb 11, 2023

@growly Have you found a solution now? thank you!

@growly
Copy link
Author

growly commented Feb 11, 2023

I gave up trying to include gflags and glog as subdirectories with my source, I now rely on a system-wide install and find_package. The project CMakeLists is here. I was hoping to make installation and dependency control a little simpler by doing it the subdirectory way, but this will have to do.

@eAzure
Copy link

eAzure commented Feb 11, 2023

I gave up trying to include gflags and glog as subdirectories with my source, I now rely on a system-wide install and find_package. The project CMakeLists is here. I was hoping to make installation and dependency control a little simpler by doing it the subdirectory way, but this will have to do.

I think I have to change to your way, thank you!

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

No branches or pull requests

4 participants