OpenBluetoothToolbox / SimpleBLE

SimpleBLE - the all-in-one Bluetooth library for MacOS, iOS, Windows, Linux and Android.
https://www.simpleble.org
Other
619 stars 107 forks source link

Missing CMake config #296

Closed PawelKorsak closed 4 months ago

PawelKorsak commented 4 months ago

Hi,

I tried to run a simple project with simpleble library. For portability I was planning on using FetchContent for library import. I was following an exemplary code found in the documentation.

I have countered the following error:

  By not providing "Findsimpleble.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "simpleble", but CMake did not find one.

  Could not find a package configuration file provided by "simpleble" with
  any of the following names:

    simplebleConfig.cmake
    simpleble-config.cmake

  Add the installation prefix of "simpleble" to CMAKE_PREFIX_PATH or set
  "simpleble_DIR" to a directory containing one of the above files.  If
  "simpleble" provides a separate development package or SDK, be sure it has
  been installed. 

For reference the code used in the main CMakeLists.txt:

cmake_minimum_required(VERSION 3.25)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(auto-speaker)
add_compile_options(${PROJECT_NAME} -Wall -Wextra -pedantic)

include(${CMAKE_SOURCE_DIR}/cmake/Findsimpleble.cmake)

find_package(simpleble REQUIRED IMPORTED)

include_directories(${CMAKE_SOURCE_DIR}/inc)

add_executable(auto-speaker ${CMAKE_SOURCE_DIR}/src/main.cc)

target_link_libraries(auto-speaker simpleble::simpleble)

And the Findsimpleble.cmake:

include(FetchContent)
FetchContent_Declare(
    simpleble
    GIT_REPOSITORY https://github.com/OpenBluetoothToolbox/SimpleBLE.git
    GIT_TAG v0.7.1
    GIT_SHALLOW YES
)

if(NOT simpleble_POPULATED)
    FetchContent_Populate(simpleble)
    list(APPEND CMAKE_MODULE_PATH "${simpleble_SOURCE_DIR}/cmake/find")
    add_subdirectory("${simpleble_SOURCE_DIR}/simpleble" "${simpleble_BINARY_DIR}")
endif()

set(simpleble_FOUND 1)

cmake version 3.25.1

EDIT:

solved by replacing

include(${CMAKE_SOURCE_DIR}/cmake/Findsimpleble.cmake)

with

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")