0

I have a project that depends on both gflags and glog. Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.23.2)

project(demo)

include(FetchContent)

FetchContent_Declare(gflags
  URL      https://github.com/gflags/gflags/archive/v2.2.2.zip
  URL_HASH SHA256=19713a36c9f32b33df59d1c79b4958434cb005b5b47dc5400a7a4b078111d9b5
)
FetchContent_MakeAvailable(gflags)
include_directories(${gflags_BINARY_DIR}/include)


FetchContent_Declare(glog
  URL      https://github.com/google/glog/archive/v0.4.0.zip
  URL_HASH SHA256=9e1b54eb2782f53cd8af107ecf08d2ab64b8d0dc2b7f5594472f3bd63ca85cdc
)
FetchContent_MakeAvailable(glog)
include_directories(${glog_SOURCE_DIR}/src ${glog_BINARY_DIR})

add_executable(demo demo.cc)
target_link_libraries(demo glog::glog)

and my demo.cc

#include <iostream>
using namespace std;

#include <glog/logging.h>


int main(int argc, char** argv){
    gflags::ParseCommandLineFlags(&argc, &argv, true);
    google::InitGoogleLogging(argv[0]);
    LOG(INFO) << "This is INFO log information";
    return 0;
}

with the following commands

mkdir -p build
cd build
cmake ..

I got the following errors

CMake Error in build/_deps/glog-src/CMakeLists.txt:
  export called with target "glog" which requires target
  "gflags_nothreads_static" that is not in this export set, but in multiple
  other export sets:
  .../build/_deps/gflags-build/gflags-nonamespace-targets.cmake,
  .../build/_deps/gflags-build/gflags-targets.cmake.


  An exported target cannot depend upon another target which is exported
  multiple times.  Consider consolidating the exports of the
  "gflags_nothreads_static" target to a single export.

My question is how to remove the above error message by modifying my own CMakeLists.txt?

aban
  • 205
  • 2
  • 12
  • how can i disable installation of `glog` in my own `CMakelists.txt` if disabling it works? is there a way to force `glog`'s `find_package` to find my fetched `gflags` and will this solution works? – aban Nov 18 '22 at 11:27
  • 1
    `find_package(gflags)` finds your fetched `gflags`. The problem is that `gflags` project explicitly specifies **two export sets** for installing the target `gflags_nothreads_static`: [gflags-targets.cmake](https://github.com/gflags/gflags/blob/master/CMakeLists.txt#L562) and `gflags-nonamespace-targets.cmake`. This confuses CMake when it tries to process installation rule for `glog` project, which uses that target. I see no other way than disabling installation of the `glog`: https://stackoverflow.com/questions/65527126. My first comment wasn't correct about the reasoning, so I removed it. – Tsyvarev Nov 18 '22 at 14:16

0 Answers0