Skip to content

Commit

Permalink
Merge pull request #133 from ax3l/fix-pkgConfigAutotools
Browse files Browse the repository at this point in the history
CMake: pkg-config Fallback
  • Loading branch information
bluca authored Jul 20, 2017
2 parents 749522d + d1568bf commit a89d35b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.0.0)
project(cppzmq)

find_package(ZeroMQ REQUIRED)
find_package(ZeroMQ)

# libzmq autotools install: fallback to pkg-config
if(NOT ZeroMQ_FOUND)
include(${CMAKE_CURRENT_LIST_DIR}/libzmqPkgConfigFallback.cmake)
endif()

if(NOT ZeroMQ_FOUND)
message(FATAL_ERROR "ZeroMQ was NOT found!")
endif()

if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static))
message(FATAL_ERROR "ZeroMQ version not supported!")
Expand Down Expand Up @@ -51,4 +60,5 @@ install(EXPORT ${PROJECT_NAME}-targets
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
${CMAKE_SOURCE_DIR}/libzmqPkgConfigFallback.cmake
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
11 changes: 10 additions & 1 deletion cppzmqConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(ZeroMQ)
find_package(ZeroMQ)

# libzmq autotools install: fallback to pkg-config
if(NOT ZeroMQ_FOUND)
include(${CMAKE_CURRENT_LIST_DIR}/libzmqPkgConfigFallback.cmake)
endif()

if(NOT ZeroMQ_FOUND)
message(FATAL_ERROR "ZeroMQ was NOT found!")
endif()

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
Expand Down
20 changes: 20 additions & 0 deletions libzmqPkgConfigFallback.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
find_package(PkgConfig)
pkg_check_modules(PC_LIBZMQ QUIET libzmq)

set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION})
find_library(ZeroMQ_LIBRARY NAMES libzmq.so
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq.a
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})

add_library(libzmq SHARED IMPORTED)
set_property(TARGET libzmq PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PC_LIBZMQ_INCLUDE_DIRS})
set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ${ZeroMQ_LIBRARY})

add_library(libzmq-static STATIC IMPORTED ${PC_LIBZMQ_INCLUDE_DIRS})
set_property(TARGET libzmq-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PC_LIBZMQ_INCLUDE_DIRS})
set_property(TARGET libzmq-static PROPERTY IMPORTED_LOCATION ${ZeroMQ_STATIC_LIBRARY})

if(ZeroMQ_LIBRARY AND ZeroMQ_STATIC_LIBRARY)
set(ZeroMQ_FOUND ON)
endif()

0 comments on commit a89d35b

Please sign in to comment.