Skip to content

Commit

Permalink
Improve cmake package
Browse files Browse the repository at this point in the history
Dependencies are now added to the *Config.cmake. This way clients don't need to specify this anymore.
  • Loading branch information
Jeruntu authored and Jeroen Oomkes committed Dec 22, 2020
1 parent f1c2d65 commit 64d5bb6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 30 deletions.
36 changes: 28 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,36 @@ target_link_libraries(qlibssh2

target_compile_features(qlibssh2 PUBLIC cxx_std_17)

# --- Create installed package
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(PACKAGE_NAME ${CMAKE_PROJECT_NAME})

set(TARGETS_FILE ${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}/${PACKAGE_NAME}Targets.cmake)
configure_package_config_file(
cmake/${PACKAGE_NAME}Config.cmake.in
${CMAKE_BINARY_DIR}/${PACKAGE_NAME}Config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
PATH_VARS
TARGETS_FILE
)

get_filename_component(TARGETS_FILE_WLE ${TARGETS_FILE} NAME_WLE)
install(TARGETS qlibssh2
EXPORT ${PACKAGE_NAME}Config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY src/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}
)
install(EXPORT ${PACKAGE_NAME}Config
EXPORT ${TARGETS_FILE_WLE}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT ${TARGETS_FILE_WLE}
NAMESPACE QLIBSSH2::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
)
)
install(
FILES
${CMAKE_BINARY_DIR}/${PACKAGE_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
)
install(DIRECTORY src/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}
)

12 changes: 12 additions & 0 deletions cmake/QLibssh2Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@PACKAGE_INIT@

set_and_check(TARGETS_FILE "@PACKAGE_TARGETS_FILE@")

check_required_components(QLibssh2)

include(CMakeFindDependencyMacro)
find_dependency(Libssh2)
find_dependency(Qt5Core)
find_dependency(Qt5Network)

include("${TARGETS_FILE}")
27 changes: 13 additions & 14 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ class Qlibssh2Conan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
options = {}
default_options = {}
generators = "cmake"
requires = ["libssh2/[>=1.9.0]",
# "qt/5.15.2@bincrafters/stable",
"openssl/1.1.1g"]

def export_sources(self):
self.copy("src/*")
self.copy("CMakeLists.txt")
generators = "cmake_paths", "cmake_find_package"
requires = [
"libssh2/[>=1.9.0]",
"openssl/1.1.1g"
# "qt/5.15.2@bincrafters/stable",
]
exports_sources = [
"src/*",
"CMakeLists.txt",
"cmake/QLibssh2Config.cmake.in"
]

def config_options(self):
pass
Expand Down Expand Up @@ -52,17 +55,13 @@ def configure(self):

self.options["libssh2"].shared = False

def _configure_cmake(self):
def build(self):
cmake = CMake(self)
cmake.configure()
return cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()

def package_info(self):
Expand Down
8 changes: 1 addition & 7 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ cmake_minimum_required(VERSION 3.16)

project(PackageTest CXX)

find_package(Libssh2 REQUIRED CONFIG)
find_package(Qt5 REQUIRED
Core
Network
)

find_package(QLibssh2 REQUIRED)
find_package(QLibssh2 REQUIRED CONFIG)

add_executable(example example.cpp)

Expand Down
2 changes: 1 addition & 1 deletion test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Qlibssh2TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake_paths"
generators = "cmake_paths", "cmake_find_package"

def build(self):
cmake = CMake(self)
Expand Down

0 comments on commit 64d5bb6

Please sign in to comment.