From 77a92e6928b92b708d8c8634a34bca90a0d3d2de Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 2 Apr 2024 22:23:47 +0200 Subject: [PATCH 1/5] CMake: Support building as shared library / QML module. --- CMakeLists.txt | 64 +++++++++++++++++++++++++++++++++++++++++++------- qmldir.in | 2 ++ 2 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 qmldir.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ded7bc..a516957 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,15 @@ cmake_minimum_required(VERSION 3.0.0) project(quickflux VERSION 1.1.3) -option(quickflux_INSTALL "Enable the installation of targets." ON) +option(quickflux_BUILD_SHARED "Build as shared library" OFF) + +if(quickflux_BUILD_SHARED) + SET(SOVERSION_MAJOR 1) + SET(SOVERSION_MINOR 0) + SET(SOVERSION_PATCH 3) +endif() +option(quickflux_INSTALL "Enable the installation of targets." ON) if(MSVC) set_property (GLOBAL PROPERTY USE_FOLDERS ON) endif() @@ -88,14 +95,37 @@ if(MSVC) source_group("Source Files\\MOC" REGULAR_EXPRESSION "moc*") endif() -add_library(quickflux STATIC - ${quickflux_PRIVATE_SOURCES} - ${quickflux_PRIVATE_HEADERS} - ${quickflux_PUBLIC_SOURCES} - ${quickflux_PUBLIC_HEADERS} - ${moc} - ) -add_library(QuickFlux::quickflux ALIAS quickflux) +if(quickflux_BUILD_SHARED) + add_library(quickflux SHARED + ${quickflux_PRIVATE_SOURCES} + ${quickflux_PRIVATE_HEADERS} + ${quickflux_PUBLIC_SOURCES} + ${quickflux_PUBLIC_HEADERS} + ${moc} + ) + set_target_properties(quickflux + PROPERTIES + VERSION ${SOVERSION_MAJOR}.${SOVERSION_MINOR}.${SOVERSION_PATCH} + SOVERSION ${SOVERSION_MAJOR} + ) + add_library(QuickFlux::quickflux ALIAS quickflux) + + # copy qmldir file to build dir so QML unit tests can use it to import the plugin + configure_file( + qmldir.in + qmldir + ) + +else() + add_library(quickflux STATIC + ${quickflux_PRIVATE_SOURCES} + ${quickflux_PRIVATE_HEADERS} + ${quickflux_PUBLIC_SOURCES} + ${quickflux_PUBLIC_HEADERS} + ${moc} + ) + add_library(QuickFlux::quickflux ALIAS quickflux) +endif() target_link_libraries(quickflux PUBLIC @@ -168,4 +198,20 @@ if(quickflux_INSTALL) DESTINATION ${CONFIG_PACKAGE_LOCATION} ) + if(quickflux_BUILD_SHARED) + # Qt5's cmake does not export QT_IMPORTS_DIR, lets query qmake on our own for now + get_target_property(QMAKE_EXECUTABLE Qt5::qmake LOCATION) + function(QUERY_QMAKE VAR RESULT) + exec_program(${QMAKE_EXECUTABLE} ARGS "-query ${VAR}" RETURN_VALUE return_code OUTPUT_VARIABLE output ) + if(NOT return_code) + file(TO_CMAKE_PATH "${output}" output) + set(${RESULT} ${output} PARENT_SCOPE) + endif(NOT return_code) + endfunction(QUERY_QMAKE) + query_qmake(QT_INSTALL_QML QT_IMPORTS_DIR) + + set(PLUGIN_DIR ${QT_IMPORTS_DIR}/QuickFlux) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir DESTINATION ${PLUGIN_DIR}) + endif() + endif() diff --git a/qmldir.in b/qmldir.in new file mode 100644 index 0000000..7476e56 --- /dev/null +++ b/qmldir.in @@ -0,0 +1,2 @@ +module QuickFlux +plugin quickflux @CMAKE_INSTALL_FULL_LIBDIR@ From c044027ca39bd48d60eb66ea4ec41ba56e5daacb Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Fri, 5 Apr 2024 12:27:01 +0200 Subject: [PATCH 2/5] Use BUILD_SHARED_LIBS --- CMakeLists.txt | 61 +++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a516957..adfe2d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,13 +6,11 @@ cmake_minimum_required(VERSION 3.0.0) project(quickflux VERSION 1.1.3) -option(quickflux_BUILD_SHARED "Build as shared library" OFF) +option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) -if(quickflux_BUILD_SHARED) - SET(SOVERSION_MAJOR 1) - SET(SOVERSION_MINOR 0) - SET(SOVERSION_PATCH 3) -endif() +set(SOVERSION_MAJOR 1) +set(SOVERSION_MINOR 0) +set(SOVERSION_PATCH 3) option(quickflux_INSTALL "Enable the installation of targets." ON) if(MSVC) @@ -95,36 +93,27 @@ if(MSVC) source_group("Source Files\\MOC" REGULAR_EXPRESSION "moc*") endif() -if(quickflux_BUILD_SHARED) - add_library(quickflux SHARED - ${quickflux_PRIVATE_SOURCES} - ${quickflux_PRIVATE_HEADERS} - ${quickflux_PUBLIC_SOURCES} - ${quickflux_PUBLIC_HEADERS} - ${moc} - ) - set_target_properties(quickflux - PROPERTIES - VERSION ${SOVERSION_MAJOR}.${SOVERSION_MINOR}.${SOVERSION_PATCH} - SOVERSION ${SOVERSION_MAJOR} - ) - add_library(QuickFlux::quickflux ALIAS quickflux) - - # copy qmldir file to build dir so QML unit tests can use it to import the plugin - configure_file( - qmldir.in - qmldir - ) - -else() - add_library(quickflux STATIC - ${quickflux_PRIVATE_SOURCES} - ${quickflux_PRIVATE_HEADERS} - ${quickflux_PUBLIC_SOURCES} - ${quickflux_PUBLIC_HEADERS} - ${moc} - ) - add_library(QuickFlux::quickflux ALIAS quickflux) +add_library(quickflux + ${quickflux_PRIVATE_SOURCES} + ${quickflux_PRIVATE_HEADERS} + ${quickflux_PUBLIC_SOURCES} + ${quickflux_PUBLIC_HEADERS} + ${moc} + ) +add_library(QuickFlux::quickflux ALIAS quickflux) + +if(BUILD_SHARED_LIBS) + set_target_properties(quickflux + PROPERTIES + VERSION ${SOVERSION_MAJOR}.${SOVERSION_MINOR}.${SOVERSION_PATCH} + SOVERSION ${SOVERSION_MAJOR} + ) + + # copy qmldir file to build dir so QML unit tests can use it to import the plugin + configure_file( + qmldir.in + qmldir + ) endif() target_link_libraries(quickflux From 68f1ec392a673d2d4d30238a047f0e5f1d7c732b Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Fri, 5 Apr 2024 13:51:33 +0200 Subject: [PATCH 3/5] Configure qmldir with @ ONLY (option name mangled so GitHub doesn't ping a random person) --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index adfe2d0..9fb41a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,7 @@ if(BUILD_SHARED_LIBS) configure_file( qmldir.in qmldir + @ONLY ) endif() From 96afd7aebb412ca484dff020e969fb92e26dfc5f Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Wed, 10 Apr 2024 23:30:32 +0200 Subject: [PATCH 4/5] CMakeLists.txt: Adjust CMake option in QT_IMPORTS_DIR detection code. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fb41a2..78fe16d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,7 +188,7 @@ if(quickflux_INSTALL) DESTINATION ${CONFIG_PACKAGE_LOCATION} ) - if(quickflux_BUILD_SHARED) + if(BUILD_SHARED_LIBS) # Qt5's cmake does not export QT_IMPORTS_DIR, lets query qmake on our own for now get_target_property(QMAKE_EXECUTABLE Qt5::qmake LOCATION) function(QUERY_QMAKE VAR RESULT) From a29c4d0769eb5a54d01dec8b064bc5167f947bd4 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Wed, 10 Apr 2024 23:32:07 +0200 Subject: [PATCH 5/5] CMakeLists.txt: Fix typo in SOVERSION_MINOR. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78fe16d..42651d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project(quickflux VERSION 1.1.3) option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) set(SOVERSION_MAJOR 1) -set(SOVERSION_MINOR 0) +set(SOVERSION_MINOR 1) set(SOVERSION_PATCH 3) option(quickflux_INSTALL "Enable the installation of targets." ON)