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 2d573fb9c..de7d01815 100644 --- a/README.rst +++ b/README.rst @@ -75,7 +75,7 @@ Dependencies ------------ * Qt >5.15 -* CMake 3.11 +* CMake 3.13 * Catch2 @@ -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..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) @@ -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,32 @@ 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. A plain ``set()`` works. The cache form and ``-DBUILD_SHARED_LIBS=OFF`` work too. + +.. code-block:: cmake + + set(BUILD_SHARED_LIBS OFF) + add_subdirectory(external/nodeeditor) + Using vcpkg ----------- @@ -109,6 +137,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 ---------------------- 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:**