Skip to content
Permalink
Browse files
Fix misuse of find_package and find_dependency in CelixConfig.cmake.
Use find_dependency without REQUIRED to handle find_package(Celix) correctly (i.e., use Celix as an optional package).
  • Loading branch information
PengZheng committed Mar 8, 2022
1 parent ecd4a51 commit ba8632467f684908581473e638f75f619a08f89c
Showing 3 changed files with 12 additions and 47 deletions.
@@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

find_package(CURL REQUIRED)

#Create shared library
add_library(civetweb_shared SHARED
@@ -73,25 +73,26 @@ set(CELIX_SHELL_TUI_BUNDLE ${CELIX_BUNDLES_DIR}/shell_tui.zip)

include(CMakeFindDependencyMacro)

find_dependency(ZLIB REQUIRED) #Needed by framework
find_dependency(UUID REQUIRED) #Needed by framework
find_dependency(CURL REQUIRED) #Needed by framework (used for curl initialization)
find_dependency(ZLIB) #Needed by framework
find_dependency(UUID) #Needed by framework
find_dependency(CURL) #Needed by framework (used for curl initialization)
find_dependency(LIBZIP) #Needed by utils
find_dependency(Jansson REQUIRED) #Needed by dfi, etcdlib, remote services, pubsub
find_dependency(Jansson) #Needed by dfi, etcdlib, remote services, pubsub
find_dependency(FFI) #Needed by dfi

if (TARGET Celix::dfi)
find_dependency(FFI REQUIRED)
find_dependency(FFI)
endif()
if (TARGET Celix::RsaConfiguredDiscovery)
find_dependency(RapidJSON REQUIRED)
find_dependency(RapidJSON)
endif ()
if (TARGET Celix::rsa_discovery_common)
find_dependency(LibXml2 REQUIRED)
find_dependency(LibXml2)
endif ()
if (TARGET Celix::celix_pubsub_admin_zmq OR TARGET Celix::celix_pubsub_admin_zmq_v2)
find_dependency(ZMQ REQUIRED)
find_dependency(CZMQ REQUIRED)
find_dependency(ZMQ)
find_dependency(CZMQ)
endif ()
if (TARGET Celix::pubsub_admin_nanomsg)
find_dependency(NanoMsg REQUIRED)
find_dependency(NanoMsg)
endif ()
@@ -28,40 +28,3 @@ include(${CELIX_CMAKE_DIRECTORY}/ContainerPackaging.cmake)
include(${CELIX_CMAKE_DIRECTORY}/DockerPackaging.cmake)
include(${CELIX_CMAKE_DIRECTORY}/Runtimes.cmake)
include(${CELIX_CMAKE_DIRECTORY}/Generic.cmake)

#find required packages
find_package(CURL REQUIRED) #framework, etcdlib
find_package(ZLIB REQUIRED) #framework
find_package(UUID REQUIRED) #framework
find_package(Jansson REQUIRED) #etcdlib, dfi
find_package(FFI REQUIRED) #dfi

if (NOT TARGET ZLIB::ZLIB)
#Note more recent zlib will create ZLIB::ZLIB target
message("Note ZLIB::ZLIB target not created by find_package(ZLIB). Creating ZLIB::ZLIB Target.")
add_library(ZLIB::ZLIB SHARED IMPORTED)
set_target_properties(ZLIB::ZLIB PROPERTIES
IMPORTED_LOCATION "${ZLIB_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}"
)
endif ()

if (NOT TARGET CURL::libcurl)
#Note more recent curl will create CURL::libcurl target
message("Note CURL::libcurl target not created by find_package(CURL). Creating CURL::libcurl Target.")
add_library(CURL::libcurl SHARED IMPORTED)
set_target_properties(CURL::libcurl PROPERTIES
IMPORTED_LOCATION "${CURL_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}"
)
endif ()

if (NOT TARGET Jansson)
#Note if JanssonConfig is present on system this is not needed
message("Note Jansson target not created by find_package(Jansson). Creating Jansson Target.")
add_library(Jansson SHARED IMPORTED)
set_target_properties(Jansson PROPERTIES
IMPORTED_LOCATION "${JANSSON_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${JANSSON_INCLUDE_DIR}"
)
endif ()

0 comments on commit ba86324

Please sign in to comment.