Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Support building as shared library / QML module. #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 55 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should define BUILD_SHARED_LIBS, the CMake-integrated way of controlling this? https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html


if(quickflux_BUILD_SHARED)
SET(SOVERSION_MAJOR 1)
SET(SOVERSION_MINOR 0)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Project version above is 1.1.3, where does the 0 here come from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch! Typo.

SET(SOVERSION_PATCH 3)
endif()

option(quickflux_INSTALL "Enable the installation of targets." ON)
if(MSVC)
set_property (GLOBAL PROPERTY USE_FOLDERS ON)
endif()
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See question about BUILD_SHARED_LIBS above, that would alleviate the need for duplicating all of this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OPNA2608 You are a much better CMake dev than I am. Could you come up with a follow-up PR bringing this more into harmony?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted as a PR to this branch: sunweaver#1

  • Use BUILD_SHARED_LIBS for determining static/dynamic library
  • Directly use PROJECT_VERSION for library versioning
  • Configure qmldir with @ONLY

${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
Expand Down Expand Up @@ -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()
2 changes: 2 additions & 0 deletions qmldir.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module QuickFlux
plugin quickflux @CMAKE_INSTALL_FULL_LIBDIR@