From a6e485f78627787dc38e969fe589ee559e7b193a Mon Sep 17 00:00:00 2001 From: Dmitry Pinaev Date: Sun, 22 Nov 2026 22:23:08 +0100 Subject: [PATCH 1/2] Explain shared and static builds in the docs Describe BUILD_SHARED_LIBS, the NODE_EDITOR_* definitions that the library sets, and why users must not define them. Note that Qt stays a dependency and that a plain set() does not reach add_subdirectory. Fix the BUILD_TESTING and BUILD_EXAMPLES defaults. Add an FAQ entry. --- README.rst | 3 ++ docs/faq.rst | 6 ++++ docs/getting-started/installation.rst | 41 +++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 2d573fb9c..e1d611413 100644 --- a/README.rst +++ b/README.rst @@ -128,6 +128,9 @@ For building a static lib use: cmake .. -DBUILD_SHARED_LIBS=off +See the "Shared and static library" section of the installation docs +(``docs/getting-started/installation.rst``) for what the library defines and what to avoid. + Linux ----- diff --git a/docs/faq.rst b/docs/faq.rst index 929a26867..25ec08a0e 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -144,6 +144,12 @@ Ensure you're using the correct build type: cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . --config Release +**Error "Cannot link against shared and static simultaneously"** + +Your target defines ``NODE_EDITOR_STATIC`` or ``NODE_EDITOR_SHARED`` by hand. QtNodes already +defines the right one for you. Remove your definition and choose the type with +``BUILD_SHARED_LIBS``. See :doc:`getting-started/installation`. + Performance Questions --------------------- diff --git a/docs/getting-started/installation.rst b/docs/getting-started/installation.rst index 1a9e6c3ad..c19e39b2a 100644 --- a/docs/getting-started/installation.rst +++ b/docs/getting-started/installation.rst @@ -58,13 +58,15 @@ CMake Options - Build with Qt6. Set to ``OFF`` for Qt5. * - ``BUILD_SHARED_LIBS`` - ``ON`` - - Build as shared library. Set to ``OFF`` for static. + - Build as shared library. Set to ``OFF`` for static. See + `Shared and static library`_. * - ``BUILD_TESTING`` - - ``ON`` - - Build unit tests. Requires Catch2. + - ``ON`` or ``OFF`` + - Build unit tests. Requires Catch2. ``ON`` when QtNodes is the top-level project, ``OFF`` + when it is added with ``add_subdirectory``. * - ``BUILD_EXAMPLES`` - - ``ON`` - - Build example applications. + - ``ON`` or ``OFF`` + - Build example applications. Same default as ``BUILD_TESTING``. **Examples:** @@ -79,6 +81,33 @@ CMake Options # Skip tests (if Catch2 not installed) cmake .. -DBUILD_TESTING=OFF +Shared and static library +------------------------- + +Choose the library type with ``BUILD_SHARED_LIBS``. The default is ``ON`` (shared). + +.. code-block:: bash + + cmake .. -DBUILD_SHARED_LIBS=OFF + +- QtNodes defines ``NODE_EDITOR_SHARED`` or ``NODE_EDITOR_STATIC`` for you. The definition is + public, so your target gets it when you link ``QtNodes::QtNodes``. This works with + ``add_subdirectory`` and with ``find_package``. In an installed package the choice is fixed + by the build that you installed. +- Do not define ``NODE_EDITOR_SHARED``, ``NODE_EDITOR_STATIC`` or ``NODE_EDITOR_EXPORTS`` + yourself. If both ``SHARED`` and ``STATIC`` are defined, the compiler stops with + ``Cannot link against shared and static simultaneously.`` +- A static QtNodes does not make Qt static. QtNodes links Qt ``Core``, ``Widgets``, ``Gui`` and + ``OpenGL`` publicly, so your application still needs Qt. +- With ``add_subdirectory`` or ``FetchContent``, set ``BUILD_SHARED_LIBS`` before QtNodes is + added, and set it in the cache. A plain ``set(BUILD_SHARED_LIBS OFF)`` has no effect on + QtNodes. + +.. code-block:: cmake + + set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) + add_subdirectory(external/nodeeditor) + Using vcpkg ----------- @@ -109,6 +138,8 @@ After running ``cmake --install .``: find_package(QtNodes REQUIRED) target_link_libraries(your_app QtNodes::QtNodes) +If you installed to a custom prefix, pass it with ``-DCMAKE_PREFIX_PATH=``. + Verifying Installation ---------------------- From cf6f26937176a3a210b3c1429adddd4d9ef72f0a Mon Sep 17 00:00:00 2001 From: Dmitry Pinaev Date: Sun, 22 Nov 2026 23:17:02 +0100 Subject: [PATCH 2/2] Honor BUILD_SHARED_LIBS set by the parent project With policy CMP0077 at the old behavior, option() removes a normal variable set by the parent. So set(BUILD_SHARED_LIBS OFF) before add_subdirectory was ignored, and QtNodes was built shared. Set CMP0077 to NEW. This needs CMake 3.13, so raise the minimum from 3.11 to 3.13. This is safe: Qt 6 needs CMake 3.16 anyway. Update the CMake version in README.rst and docs. Update the docs to say that a plain set() works. --- CMakeLists.txt | 3 ++- README.rst | 2 +- docs/getting-started/installation.rst | 7 +++---- docs/testing.rst | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b14307f0..8fc44cef3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.13) +cmake_policy(SET CMP0077 NEW) # new in 3.13. The NEW behavior of this policy is that option() keeps a normal variable set by the parent project, such as BUILD_SHARED_LIBS. cmake_policy(SET CMP0072 NEW) # new in 3.11. The NEW behavior for this policy is to set OpenGL_GL_PREFERENCE to GLVND. cmake_policy(SET CMP0068 NEW) # new in 3.9. The NEW behavior of this policy is to ignore the RPATH settings for install_name on macOS. diff --git a/README.rst b/README.rst index e1d611413..de7d01815 100644 --- a/README.rst +++ b/README.rst @@ -75,7 +75,7 @@ Dependencies ------------ * Qt >5.15 -* CMake 3.11 +* CMake 3.13 * Catch2 diff --git a/docs/getting-started/installation.rst b/docs/getting-started/installation.rst index c19e39b2a..af83c6bf6 100644 --- a/docs/getting-started/installation.rst +++ b/docs/getting-started/installation.rst @@ -6,7 +6,7 @@ Requirements - **Qt** 5.15+ or Qt 6.x - **Qt SVG module** (for processing status icons) -- **CMake** 3.11+ +- **CMake** 3.13+ - **C++ Compiler** with C++17 support (GCC 7+, Clang 5+, MSVC 2019+) - **Catch2** (optional, for running tests) @@ -100,12 +100,11 @@ Choose the library type with ``BUILD_SHARED_LIBS``. The default is ``ON`` (share - A static QtNodes does not make Qt static. QtNodes links Qt ``Core``, ``Widgets``, ``Gui`` and ``OpenGL`` publicly, so your application still needs Qt. - With ``add_subdirectory`` or ``FetchContent``, set ``BUILD_SHARED_LIBS`` before QtNodes is - added, and set it in the cache. A plain ``set(BUILD_SHARED_LIBS OFF)`` has no effect on - QtNodes. + added. A plain ``set()`` works. The cache form and ``-DBUILD_SHARED_LIBS=OFF`` work too. .. code-block:: cmake - set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) + set(BUILD_SHARED_LIBS OFF) add_subdirectory(external/nodeeditor) Using vcpkg diff --git a/docs/testing.rst b/docs/testing.rst index 6075759a5..8369e55bb 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -211,7 +211,7 @@ Tests are built automatically when ``BUILD_TESTING`` is enabled (default). **Prerequisites:** - Catch2 testing framework - Qt6 (or Qt5 with appropriate configuration) - - CMake 3.8+ + - CMake 3.13+ **Configuration:**