google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
6.93k stars 2.05k forks source link

FetchContent support #1063

Closed valaxkong closed 6 months ago

valaxkong commented 6 months ago

I saw the README said glog can be incorporated into custom projects using the CMake command add_subdirectory. I tried it like this

FetchContent_Declare(
  glog
  GIT_REPOSITORY https://github.com/google/glog.git
  GIT_TAG        v0.6.0
)
FetchContent_GetProperties(glog)
if(NOT glog_POPULATED)
  FetchContent_Populate(glog)
  add_subdirectory(${glog_SOURCE_DIR})
endif()

When building as a submodule of my projects, I found those template codes in xxx.h.in files have not been replaced to generate xxx.h file. How to do things right? Thanks for your help.

valaxkong commented 6 months ago

I found the solutions.

FetchContent_Declare(
  glog
  GIT_REPOSITORY https://github.com/google/glog.git
  GIT_TAG        v0.6.0
)
FetchContent_GetProperties(glog)
if(NOT glog_POPULATED)
  FetchContent_Populate(glog)
  add_subdirectory(${glog_SOURCE_DIR} ${glog_BINARY_DIR})
endif()

And I will give a PR later.

sergiud commented 6 months ago

add_subdirectory mentioned in the docs does not use FetchContent. You need to specify the build directory only for the latter explicitly.

sergiud commented 6 months ago

The issue is not actionable. You can however extend the README with a link to CMake reference documentation that explains how to use FetchContent correctly if you want.

valaxkong commented 6 months ago

@sergiud I opened a PR which gives an example to show the usage of FetchContent and add_subdirectory. https://github.com/google/glog/pull/1067