-
Notifications
You must be signed in to change notification settings - Fork 74
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
77a92e6
c044027
68f1ec3
96afd7a
a29c4d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See question about There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Submitted as a PR to this branch: sunweaver#1
|
||
${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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module QuickFlux | ||
plugin quickflux @CMAKE_INSTALL_FULL_LIBDIR@ |
There was a problem hiding this comment.
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