Skip to content

Commit

Permalink
refactor(build): Make the dependencies not exposed in the API private
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Jul 1, 2024
1 parent 2b291ef commit 7ac2bbc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
21 changes: 12 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,11 @@ endif()
######################

set(open62541_LIBRARIES "")
set(open62541_PUBLIC_LIBRARIES "")
if("${UA_ARCHITECTURE}" STREQUAL "posix")
list(APPEND open62541_LIBRARIES "m")
if(UA_MULTITHREADING OR UA_BUILD_UNIT_TESTS)
list(APPEND open62541_LIBRARIES "pthread")
if(UA_MULTITHREADING GREATER_EQUAL 100 OR UA_BUILD_UNIT_TESTS)
list(APPEND open62541_PUBLIC_LIBRARIES "pthread")
endif()
if(NOT APPLE AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
list(APPEND open62541_LIBRARIES "rt")
Expand Down Expand Up @@ -1421,7 +1422,8 @@ SET_TARGET_PROPERTIES(open62541 PROPERTIES
VERSION "${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}")

# DLL requires linking to dependencies
target_link_libraries(open62541 ${open62541_LIBRARIES})
target_link_libraries(open62541 PUBLIC ${open62541_PUBLIC_LIBRARIES})
target_link_libraries(open62541 PRIVATE ${open62541_LIBRARIES})

##########################
# Build Selected Targets #
Expand Down Expand Up @@ -1491,7 +1493,6 @@ install(TARGETS open62541

set(open62541_install_tools_dir share/open62541)
set(open62541_install_schema_dir share/open62541/schema)
set(open62541_crypto_plugin ${UA_ENABLE_ENCRYPTION})

# Create open62541Config.cmake
include(CMakePackageConfigHelpers)
Expand All @@ -1500,8 +1501,7 @@ configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/open62541
"${CMAKE_CURRENT_BINARY_DIR}/open62541Config.cmake"
INSTALL_DESTINATION "${cmake_configfile_install}"
PATH_VARS open62541_install_tools_dir
open62541_install_schema_dir
open62541_crypto_plugin)
open62541_install_schema_dir)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/open62541Config.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/open62541Macros.cmake"
DESTINATION "${cmake_configfile_install}")
Expand All @@ -1527,10 +1527,13 @@ export(TARGETS open62541
if(UA_ENABLE_AMALGAMATION)
set(PC_EXTRA_CFLAGS "-DUA_ENABLE_AMALGAMATION")
endif()
set(pkgcfglibs "-lopen62541")
foreach(lib ${open62541_LIBRARIES})
set(pkgcfglibs "${pkgcfglibs} -l${lib}")

set(pkgcfgpubliclibs "")
foreach(lib ${open62541_PUBLIC_LIBRARIES})
set(pkgcfgpubliclibs "${pkgcfgpubliclibs}-l${lib} ")
endforeach()

string(REPLACE ";" ", " pkgcfglibs "${open62541_LIBRARIES}")
configure_file(tools/open62541.pc.in ${PROJECT_BINARY_DIR}/src_generated/open62541.pc @ONLY)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
Expand Down
12 changes: 0 additions & 12 deletions tools/cmake/open62541Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/open62541Targets.cmake")

set_and_check(open62541_TOOLS_DIR @PACKAGE_open62541_install_tools_dir@ CACHE PATH "Path to the directory that contains the tooling of the stack")
set_and_check(UA_SCHEMA_DIR @PACKAGE_open62541_install_schema_dir@ CACHE PATH "Path to the directory that contains the schema files")
set(open62541_crypto_plugin @open62541_crypto_plugin@)

# Macros for datatype generation, nodeset compiler, etc.
include("${CMAKE_CURRENT_LIST_DIR}/open62541Macros.cmake")

check_required_components(open62541)

include(CMakeFindDependencyMacro)
if(open62541_crypto_plugin STREQUAL "MBEDTLS")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
find_dependency(MbedTLS REQUIRED)
list(REMOVE_AT CMAKE_MODULE_PATH -1)
elseif(open62541_crypto_plugin STREQUAL "OPENSSL")
find_dependency(OpenSSL REQUIRED)
elseif(open62541_crypto_plugin STREQUAL "LIBRESSL")
find_dependency(LibreSSL REQUIRED)
endif()
3 changes: 2 additions & 1 deletion tools/open62541.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: open62541
Description: open62541 is an open source C (C99) implementation of OPC UA
Version: @OPEN62541_VER_MAJOR@.@OPEN62541_VER_MINOR@.@OPEN62541_VER_PATCH@@OPEN62541_VER_LABEL@
Libs: -L${libdir} @pkgcfglibs@
Libs: -L${libdir} -lopen62541 @pkgcfgpubliclibs@
Requires.private: @pkgcfglibs@
Cflags: -I${includedir} @PC_EXTRA_CFLAGS@

0 comments on commit 7ac2bbc

Please sign in to comment.