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?