dropshell/runner/CMakeLists.txt
Your Name b5bc7b611d
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 21s
Runner.
2025-05-10 12:43:25 +12:00

90 lines
2.5 KiB
CMake

cmake_minimum_required(VERSION 3.10)
project(runner VERSION 1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Include directories
include_directories(include)
# Find required packages
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
include(FetchContent)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
)
FetchContent_MakeAvailable(nlohmann_json)
endif()
# Try to find libssh using different methods
find_package(libssh QUIET)
if(NOT libssh_FOUND)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBSSH libssh QUIET)
endif()
if(NOT LIBSSH_FOUND)
# Try to find manually if pkg-config failed too
find_path(LIBSSH_INCLUDE_DIR
NAMES libssh/libssh.h
PATHS /usr/include /usr/local/include
)
find_library(LIBSSH_LIBRARY
NAMES ssh libssh
PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu
)
if(LIBSSH_INCLUDE_DIR AND LIBSSH_LIBRARY)
set(LIBSSH_FOUND TRUE)
set(LIBSSH_LIBRARIES ${LIBSSH_LIBRARY})
set(LIBSSH_INCLUDE_DIRS ${LIBSSH_INCLUDE_DIR})
message(STATUS "Found libssh: ${LIBSSH_LIBRARY}")
else()
message(FATAL_ERROR "libssh not found. Please install libssh-dev package.\nOn Ubuntu/Debian: sudo apt install libssh-dev\nOn CentOS/RHEL: sudo yum install libssh-devel\nOn macOS: brew install libssh")
endif()
endif()
endif()
# Print libssh information for debugging
message(STATUS "LIBSSH_FOUND: ${LIBSSH_FOUND}")
message(STATUS "LIBSSH_LIBRARIES: ${LIBSSH_LIBRARIES}")
message(STATUS "LIBSSH_INCLUDE_DIRS: ${LIBSSH_INCLUDE_DIRS}")
find_package(Threads REQUIRED)
# Library target
add_library(dropshell_runner STATIC
src/runner.cpp
src/base64.cpp
)
target_include_directories(dropshell_runner PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBSSH_INCLUDE_DIRS}
)
# Link with libssh
if(libssh_FOUND)
# libssh was found using the find_package method
target_link_libraries(dropshell_runner PUBLIC
nlohmann_json::nlohmann_json
ssh
Threads::Threads
)
else()
# libssh was found using pkg-config or manual search
target_link_libraries(dropshell_runner PUBLIC
nlohmann_json::nlohmann_json
${LIBSSH_LIBRARIES}
Threads::Threads
)
endif()
# Executable target
add_executable(runner src/main.cpp)
target_link_libraries(runner PRIVATE dropshell_runner)