1

Following is my CMakeLists.txt structure

|-- MyProject
    |-- CMakeLists.txt
    |-- README.md
    |-- bin
    |-- include
    |-- lib
    |-- src
    |   |-- CMakeLists.txt
    |   |-- main.cc
    |   |-- parser
    |       |-- CMakeLists.txt
    |       |-- parser.cc
    |       |-- parser.h
    |-- third-party
        |-- CMakeLists.txt
        |-- cassandra-cpp-driver

Now I want to introduce a yugabyteDB-cpp-driver https://github.com/yugabyte/cassandra-cpp-driver/tree/2.9.0-yb to use its API, so I add those commands into my root CMakeLists.txt

set(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/third-party)

add_subdirectory(${THIRD_PARTY_DIR})

Then I add these to third-party/CMakeLists.txt

set(CQL_DRIVER_LIB_NAME "cassandra-cpp-driver")
set(CQL_DRIVER_INC_PATH ${CQL_DRIVER_LIB_NAME}/include)

add_subdirectory(${CQL_DRIVER_LIB_NAME})

After these, when I trying to do build the project, I got

CMake Error at third-party/cassandra-cpp-driver/CMakeLists.txt:10 (include):
  include could not find requested file:

    CppDriver


CMake Error at third-party/cassandra-cpp-driver/CMakeLists.txt:12 (CassInitProject):
  Unknown CMake command "CassInitProject".

Seems the cpp-driver it self has a include() command which calls the .cmake files the git contains, but I can't trigger it in my project.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
luvcode02
  • 21
  • 1
  • 4
  • Read the documentation - here: https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html#guide:Using%20Dependencies%20Guide and here: https://cmake.org/cmake/help/latest/command/find_package.html – Jesper Juhl Sep 10 '22 at 07:35
  • @JesperJuhl I dont think this work... Because the `CppDriver.cmake` in the third-party lib doesn't match nor pattern... – luvcode02 Sep 10 '22 at 08:34

1 Answers1

1

Note: Below I describe a solution to the specific problem occuring, but this is in no way a complete solution to allow you to include the project the way you intend to. This is unlikely to be possible without modifying the third party cmake logic. The cmake logic just doesn't seem to be designed for your intended use case.


CMake Error at third-party/cassandra-cpp-driver/CMakeLists.txt:10 (include):
  include could not find requested file:

    CppDriver

The relevant lines in the CMakeLists.txt file in the repository linked are

set(CASS_ROOT_DIR ${CMAKE_SOURCE_DIR})
...
list(APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR}/cmake/modules)

include(CppDriver)

The first line is supposed to make cmake able to the CppDriver.cmake module when using the include() command.

CMAKE_SOURCE_DIR refers to the directory containg the toplevel CMakeLists.txt though, which is your own directory. To be able to include the project via add_subdirectory, the relevant line should read

set(CASS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

(Note: In no way this is a complete analysis of the cmake logic. There may be different parts that would require similar adjustments.)

You could fix this specific error by simply adding the correct path before using add_subdirectory():

set(CQL_DRIVER_LIB_NAME "cassandra-cpp-driver")
set(CQL_DRIVER_INC_PATH ${CQL_DRIVER_LIB_NAME}/include)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${CQL_DRIVER_LIB_NAME}/cmake/modules)

add_subdirectory(${CQL_DRIVER_LIB_NAME})

But you'd just run into a similar issue in a different place in the third party cmake logic.

fabian
  • 80,457
  • 12
  • 86
  • 114
  • Thanks for your answer! After reconsider my needs, I thought your " The cmake logic just doesn't seem to be designed for your intended use case." is true. So I decided just install the lib then use it – luvcode02 Sep 11 '22 at 12:58