diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-24 17:41:35 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-24 18:18:31 +0100 |
| commit | 3e8111aaee070dc9b5d51cab3fd44ff88841f63e (patch) | |
| tree | 887ca52741c8f9b62a950f2670ddfb4bee348c5d /CMakeLists.txt | |
| parent | c47f6a35ea0cb14936bb0d6470d6543965a6b5e2 (diff) | |
| download | BobinkQtOpcUa-3e8111aaee070dc9b5d51cab3fd44ff88841f63e.tar.gz BobinkQtOpcUa-3e8111aaee070dc9b5d51cab3fd44ff88841f63e.zip | |
Make build system usable as a git submodule
Replace CMAKE_SOURCE_DIR/CMAKE_BINARY_DIR with PROJECT_SOURCE_DIR/
PROJECT_BINARY_DIR so paths resolve correctly from add_subdirectory().
Guard global settings (CMAKE_CXX_STANDARD, CMAKE_BUILD_RPATH,
qt_standard_project_setup, demo) behind PROJECT_IS_TOP_LEVEL.
Export OPEN62541_INSTALL_DIR and QTOPCUA_INSTALL_DIR as CACHE INTERNAL
so parent projects can set up RPATH and plugin paths.
Diffstat (limited to 'CMakeLists.txt')
| -rw-r--r-- | CMakeLists.txt | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f35b498..51b90e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,11 @@ cmake_minimum_required(VERSION 3.16) project(BobinkQtOpcUa LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +endif() # Build external dependencies (open62541, qtopcua) if not already built include(cmake/BuildDeps.cmake) @@ -19,21 +21,27 @@ set(Qt6DeclarativeOpcua_DIR "${QTOPCUA_INSTALL_DIR}/lib/cmake/Qt6DeclarativeOpcu list(PREPEND CMAKE_PREFIX_PATH "${OPEN62541_INSTALL_DIR}") find_package(Qt6 6.10.2 REQUIRED COMPONENTS Core Qml Quick OpcUa) -qt_standard_project_setup(REQUIRES 6.10.2) - -# Set path for qmllint -set(QML_IMPORT_PATH - "${CMAKE_CURRENT_BINARY_DIR}/qml" - CACHE STRING "Path to locally built qml") -# Generate .qmlls.ini for QML Language Server. Useful once QtOpcUa is installed -# globally (qt-cmake --install build/deps/qtopcua-build) so qmlls can resolve -# all Qt QML imports without extra importPaths. set(QT_QML_GENERATE_QMLLS_INI ON -# CACHE BOOL "") - -# Ensure the local QtOpcUa and open62541 libs are findable at runtime (needed -# because the Qt plugin loader dlopen's the open62541 backend). -set(CMAKE_BUILD_RPATH "${QTOPCUA_INSTALL_DIR}/lib" - "${OPEN62541_INSTALL_DIR}/lib") + +if(PROJECT_IS_TOP_LEVEL) + qt_standard_project_setup(REQUIRES 6.10.2) + + # Set path for qmllint + set(QML_IMPORT_PATH + "${CMAKE_CURRENT_BINARY_DIR}/qml" + CACHE STRING "Path to locally built qml") + # Generate .qmlls.ini for QML Language Server. Useful once QtOpcUa is installed + # globally (qt-cmake --install build/deps/qtopcua-build) so qmlls can resolve + # all Qt QML imports without extra importPaths. set(QT_QML_GENERATE_QMLLS_INI ON + # CACHE BOOL "") + + # Ensure the local QtOpcUa and open62541 libs are findable at runtime (needed + # because the Qt plugin loader dlopen's the open62541 backend). + set(CMAKE_BUILD_RPATH "${QTOPCUA_INSTALL_DIR}/lib" + "${OPEN62541_INSTALL_DIR}/lib") +endif() add_subdirectory(src) -add_subdirectory(demo) + +if(PROJECT_IS_TOP_LEVEL) + add_subdirectory(demo) +endif() |
