Skip to content

Commit

Permalink
Add ability to build as static libraries (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej authored Jan 27, 2024
1 parent 2696f18 commit a70dd2a
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 41 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ include(cmake/helpers.cmake)
# Options
option(MLN_QT_WITH_LOCATION "Build QMapLibreLocation" ON)
option(MLN_QT_WITH_WIDGETS "Build QMapLibreWidgets" ON)
option(MLN_QT_STATIC "Build QMapLibre staticaly (force static build with Qt6)" OFF)
option(MLN_QT_WITH_COVERAGE "Build QMapLibre with code coverage collection" OFF)
option(MLN_QT_WITH_CLANG_TIDY "Build QMapLibre with clang-tidy checks enabled" OFF)

Expand Down
12 changes: 10 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ set(Core_Headers ${MLN_QT_NAME_LOWERCASE}.hpp ${Core_Headers} ${Core_Headers_Gen

# Make a Qt library
if(COMMAND qt_add_library)
qt_add_library(Core)
if(MLN_QT_STATIC)
qt_add_library(Core STATIC)
else()
qt_add_library(Core)
endif()
else()
add_library(Core SHARED)
if(MLN_QT_STATIC)
add_library(Core STATIC)
else()
add_library(Core SHARED)
endif()
endif()
add_library(${MLN_QT_NAME}::Core ALIAS Core)

Expand Down
12 changes: 10 additions & 2 deletions src/location/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Make a Qt library
if(COMMAND qt_add_library)
qt_add_library(Location)
if(MLN_QT_STATIC)
qt_add_library(Location STATIC)
else()
qt_add_library(Location)
endif()
else()
add_library(Location SHARED)
if(MLN_QT_STATIC)
add_library(Location STATIC)
else()
add_library(Location SHARED)
endif()
endif()
add_library(${MLN_QT_NAME}::Location ALIAS Location)

Expand Down
110 changes: 75 additions & 35 deletions src/location/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
# QtLocation plugin
if(COMMAND qt_add_plugin)
qt_add_plugin(
${MLN_QT_GEOSERVICES_PLUGIN}
CLASS_NAME QGeoServiceProviderFactoryMapLibre
OUTPUT_TARGETS GeoServicesPluginOutputTargets
PLUGIN_TYPE geoservices
qgeoserviceproviderplugin.cpp qgeoserviceproviderplugin.hpp

$<$<PLATFORM_ID:Windows>:${CMAKE_BINARY_DIR}/version_info.rc>
)
if(MLN_QT_STATIC)
qt_add_plugin(
${MLN_QT_GEOSERVICES_PLUGIN}
STATIC
CLASS_NAME QGeoServiceProviderFactoryMapLibre
OUTPUT_TARGETS GeoServicesPluginOutputTargets
PLUGIN_TYPE geoservices
)
else()
qt_add_plugin(
${MLN_QT_GEOSERVICES_PLUGIN}
CLASS_NAME QGeoServiceProviderFactoryMapLibre
OUTPUT_TARGETS GeoServicesPluginOutputTargets
PLUGIN_TYPE geoservices
)
endif()
else()
add_library(
${MLN_QT_GEOSERVICES_PLUGIN}
SHARED
if(MLN_QT_STATIC)
add_library(${MLN_QT_GEOSERVICES_PLUGIN} STATIC)
else()
add_library(${MLN_QT_GEOSERVICES_PLUGIN} SHARED)
endif()
target_compile_definitions(${MLN_QT_GEOSERVICES_PLUGIN} PRIVATE QT_PLUGIN)
endif()

target_sources(
${MLN_QT_GEOSERVICES_PLUGIN}
PRIVATE
qgeoserviceproviderplugin.cpp qgeoserviceproviderplugin.hpp

$<$<PLATFORM_ID:Windows>:${CMAKE_BINARY_DIR}/version_info.rc>
)
target_compile_definitions(${MLN_QT_GEOSERVICES_PLUGIN} PRIVATE QT_PLUGIN)
endif()
)

# QtLocation plugin extra target properties
set_target_properties(
Expand Down Expand Up @@ -82,19 +95,36 @@ set(Plugin_Sources
)

if(COMMAND qt_add_qml_module)
qt_add_qml_module(
${MLN_QT_QML_PLUGIN}
URI QtLocation.MapLibre
VERSION ${PROJECT_VERSION}
PLUGIN_TARGET ${MLN_QT_QML_PLUGIN}
NO_PLUGIN_OPTIONAL
NO_GENERATE_QMLDIR
CLASS_NAME QtLocationMapLibreQmlModule
RESOURCE_PREFIX "/"
OUTPUT_DIRECTORY "QtLocation/MapLibre"
OUTPUT_TARGETS QmlPluginOutputTargets
SOURCES ${Plugin_Sources}
)
if(MLN_QT_STATIC)
qt_add_qml_module(
${MLN_QT_QML_PLUGIN}
STATIC
URI QtLocation.MapLibre
VERSION ${PROJECT_VERSION}
PLUGIN_TARGET ${MLN_QT_QML_PLUGIN}
NO_PLUGIN_OPTIONAL
NO_GENERATE_QMLDIR
CLASS_NAME QtLocationMapLibreQmlModule
RESOURCE_PREFIX "/"
OUTPUT_DIRECTORY "QtLocation/MapLibre"
OUTPUT_TARGETS QmlPluginOutputTargets
SOURCES ${Plugin_Sources}
)
else()
qt_add_qml_module(
${MLN_QT_QML_PLUGIN}
URI QtLocation.MapLibre
VERSION ${PROJECT_VERSION}
PLUGIN_TARGET ${MLN_QT_QML_PLUGIN}
NO_PLUGIN_OPTIONAL
NO_GENERATE_QMLDIR
CLASS_NAME QtLocationMapLibreQmlModule
RESOURCE_PREFIX "/"
OUTPUT_DIRECTORY "QtLocation/MapLibre"
OUTPUT_TARGETS QmlPluginOutputTargets
SOURCES ${Plugin_Sources}
)
endif()
set_target_properties(
${MLN_QT_QML_PLUGIN}
PROPERTIES
Expand All @@ -107,13 +137,23 @@ if(COMMAND qt_add_qml_module)
@ONLY
)
else()
add_library(
${MLN_QT_QML_PLUGIN}
SHARED
${Plugin_Sources}
legacy/qml_module.cpp
legacy/qml_registration.cpp
)
if(MLN_QT_STATIC)
add_library(
${MLN_QT_QML_PLUGIN}
STATIC
${Plugin_Sources}
legacy/qml_module.cpp
legacy/qml_registration.cpp
)
else()
add_library(
${MLN_QT_QML_PLUGIN}
SHARED
${Plugin_Sources}
legacy/qml_module.cpp
legacy/qml_registration.cpp
)
endif()
target_compile_definitions(
${MLN_QT_QML_PLUGIN}
PRIVATE
Expand Down
12 changes: 10 additions & 2 deletions src/widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ set(Widgets_Headers ${MLN_QT_WIDGETS_LOWERCASE}.hpp ${Widgets_Headers} ${Widgets

# Make a Qt library
if(COMMAND qt_add_library)
qt_add_library(Widgets)
if(MLN_QT_STATIC)
qt_add_library(Widgets STATIC)
else()
qt_add_library(Widgets)
endif()
else()
add_library(Widgets SHARED)
if(MLN_QT_STATIC)
add_library(Widgets STATIC)
else()
add_library(Widgets SHARED)
endif()
endif()
add_library(${MLN_QT_NAME}::Widgets ALIAS Core)

Expand Down

0 comments on commit a70dd2a

Please sign in to comment.