Skip to content

Commit

Permalink
CMake coding style unification (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej authored Dec 23, 2023
1 parent 2e3361d commit a1808ad
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 55 deletions.
25 changes: 13 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ cmake_minimum_required(VERSION 3.19...3.21)

# Version
file(READ "VERSION.txt" MLN_QT_VERSION)
string(REGEX REPLACE "\n" "" MLN_QT_VERSION "${MLN_QT_VERSION}") # get rid of the newline at the end
string(STRIP "${MLN_QT_VERSION}" MLN_QT_VERSION) # get rid of the whitespace
set(MLN_QT_VERSION_COMPATIBILITY 3.0.0)
message(STATUS "Version ${MLN_QT_VERSION}")

# Project definition
project(MapLibreNativeQt
project(
MapLibreNativeQt
VERSION "${MLN_QT_VERSION}"
DESCRIPTION "MapLibre Native Qt Bindings"
LANGUAGES CXX
Expand Down Expand Up @@ -38,15 +39,15 @@ option(MLN_QT_WITH_CLANG_TIDY "Build QMapLibre with clang-tidy checks enabled" O

# Find Qt
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui Network REQUIRED) # main dependencies
if (NOT MLN_QT_WITH_INTERNAL_SQLITE)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui Network REQUIRED) # main dependencies
if(NOT MLN_QT_WITH_INTERNAL_SQLITE)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Sql REQUIRED)
endif()
if (MLN_QT_WITH_LOCATION)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Location REQUIRED) # location
if(MLN_QT_WITH_LOCATION)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Location REQUIRED) # location
endif()
if (MLN_QT_WITH_WIDGETS)
if (Qt6_FOUND)
if(MLN_QT_WITH_WIDGETS)
if(Qt6_FOUND)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGLWidgets REQUIRED)
else()
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL REQUIRED)
Expand All @@ -55,7 +56,7 @@ endif()
message(STATUS "Using Qt${QT_VERSION_MAJOR}")

# Debugging & ccache on Windows
if (MSVC)
if(MSVC)
foreach(config DEBUG RELWITHDEBINFO)
foreach(lang C CXX)
set(flags_var "CMAKE_${lang}_FLAGS_${config}")
Expand All @@ -73,9 +74,9 @@ if(MLN_QT_WITH_CLANG_TIDY)
else()
message(STATUS "Found clang-tidy at ${CLANG_TIDY_COMMAND}")
endif()
# TODO: there are options which are only available on GCC(e.g. -Werror=maybe-uninitialized),
# that's why we need to disable this `unknown-warning-option` here.
# We could check if current compiler supports particular flag before enabling it.
# TODO: there are options which are only available on GCC (e.g. -Werror=maybe-uninitialized),
# that's why we need to disable this `unknown-warning-option` here. We could check if current
# compiler supports particular flag before enabling it.
set(CLANG_TIDY_COMMAND "${CLANG_TIDY_COMMAND};--extra-arg=-Wno-error=unknown-warning-option")
endif()

Expand Down
13 changes: 8 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${MLN_QT_NAME}/)
# Components
add_subdirectory(core)
set(MLN_QT_SUPPORTED_COMPONENTS "Core")
if (MLN_QT_WITH_LOCATION)
if(MLN_QT_WITH_LOCATION)
add_subdirectory(location)
list(APPEND MLN_QT_SUPPORTED_COMPONENTS "Location")
message(STATUS "Building location module")
endif()
if (MLN_QT_WITH_WIDGETS)
if(MLN_QT_WITH_WIDGETS)
add_subdirectory(widgets)
list(APPEND MLN_QT_SUPPORTED_COMPONENTS "Widgets")
message(STATUS "Building widgets module")
Expand All @@ -23,11 +23,14 @@ configure_package_config_file(
"${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR
CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO)
CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}ConfigVersion.cmake
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}ConfigVersion.cmake
VERSION ${MLN_QT_VERSION}
COMPATIBILITY AnyNewerVersion)
COMPATIBILITY AnyNewerVersion
)

install(
FILES
Expand Down
16 changes: 6 additions & 10 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ target_sources(
conversion_p.hpp
geojson.cpp geojson_p.hpp
map_observer.cpp map_observer_p.hpp
map.cpp map_p.hpp
map_renderer.cpp map_renderer_p.hpp
map.cpp map_p.hpp
renderer_backend.cpp renderer_backend_p.hpp
renderer_observer_p.hpp
scheduler.cpp scheduler_p.hpp
Expand Down Expand Up @@ -80,7 +80,7 @@ set_target_properties(
)

# Qt MOC
if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool)
if(Qt6_FOUND AND COMMAND qt_enable_autogen_tool)
qt_enable_autogen_tool(Core "moc" ON)
endif()

Expand All @@ -90,11 +90,6 @@ target_compile_definitions(
PRIVATE
QT_BUILD_MAPLIBRE_CORE_LIB
)
# static?
# target_compile_definitions(
# Core
# PUBLIC QT_MAPLIBRE_STATIC
# )

# Common include directories
target_include_directories(
Expand All @@ -121,7 +116,7 @@ target_link_libraries(
$<BUILD_INTERFACE:mbgl-core>
$<BUILD_INTERFACE:CompilerOptions>
)
if (NOT MLN_QT_WITH_INTERNAL_SQLITE)
if(NOT MLN_QT_WITH_INTERNAL_SQLITE)
target_link_libraries(
Core
PUBLIC
Expand All @@ -130,7 +125,7 @@ if (NOT MLN_QT_WITH_INTERNAL_SQLITE)
endif()

# Apple specifics
if (APPLE)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(
Core
PROPERTIES
Expand All @@ -156,7 +151,8 @@ endif()
install(
EXPORT ${MLN_QT_NAME}CoreTargets
NAMESPACE ${MLN_QT_NAMESPACE}
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/vendor/maplibre-native/include/mbgl
Expand Down
10 changes: 7 additions & 3 deletions src/location/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set_target_properties(
)

# Qt MOC
if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool)
if(Qt6_FOUND AND COMMAND qt_enable_autogen_tool)
qt_enable_autogen_tool(Location "moc" ON)
endif()

Expand Down Expand Up @@ -62,7 +62,7 @@ target_link_libraries(
)

# Apple specifics
if (APPLE)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(
Location
PROPERTIES
Expand Down Expand Up @@ -103,7 +103,11 @@ install(
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${MLN_QT_NAME}Location"
)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/macros.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}LocationMacros.cmake" COPYONLY)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/macros.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}LocationMacros.cmake"
COPYONLY
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}LocationMacros.cmake
Expand Down
49 changes: 38 additions & 11 deletions src/location/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# QtLocation plugin
if(COMMAND qt_add_plugin)
qt_add_plugin(${MLN_QT_GEOSERVICES_PLUGIN}
qt_add_plugin(
${MLN_QT_GEOSERVICES_PLUGIN}
CLASS_NAME QGeoServiceProviderFactoryMapLibre
OUTPUT_TARGETS GeoServicesPluginOutputTargets
PLUGIN_TYPE geoservices
qgeoserviceproviderplugin.cpp qgeoserviceproviderplugin.hpp
)
else()
add_library(${MLN_QT_GEOSERVICES_PLUGIN} SHARED
qgeoserviceproviderplugin.cpp qgeoserviceproviderplugin.hpp)
add_library(
${MLN_QT_GEOSERVICES_PLUGIN}
SHARED
qgeoserviceproviderplugin.cpp qgeoserviceproviderplugin.hpp
)
target_compile_definitions(${MLN_QT_GEOSERVICES_PLUGIN} PRIVATE QT_PLUGIN)
endif()

Expand Down Expand Up @@ -70,7 +74,8 @@ set(Plugin_Sources
)

if(COMMAND qt_add_qml_module)
qt_add_qml_module(${MLN_QT_QML_PLUGIN}
qt_add_qml_module(
${MLN_QT_QML_PLUGIN}
URI QtLocation.MapLibre
VERSION ${PROJECT_VERSION}
PLUGIN_TARGET ${MLN_QT_QML_PLUGIN}
Expand All @@ -82,18 +87,40 @@ if(COMMAND qt_add_qml_module)
OUTPUT_TARGETS QmlPluginOutputTargets
SOURCES ${Plugin_Sources}
)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qmldir.in" "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/qmldir" @ONLY)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/qmldir.in"
"${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/qmldir"
@ONLY
)
else()
add_library(${MLN_QT_QML_PLUGIN} SHARED ${Plugin_Sources} legacy/qml_module.cpp legacy/qml_registration.cpp)
target_compile_definitions(${MLN_QT_QML_PLUGIN} PRIVATE QT_PLUGIN)
target_include_directories(${MLN_QT_QML_PLUGIN} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add_library(
${MLN_QT_QML_PLUGIN}
SHARED
${Plugin_Sources}
legacy/qml_module.cpp
legacy/qml_registration.cpp
)
target_compile_definitions(
${MLN_QT_QML_PLUGIN}
PRIVATE
QT_PLUGIN
)
target_include_directories(
${MLN_QT_QML_PLUGIN}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
set_target_properties(
${MLN_QT_QML_PLUGIN}
PROPERTIES
AUTOMOC ON
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre"
)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/legacy/qmldir.in" "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/qmldir" @ONLY)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/legacy/qmldir.in"
"${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/qmldir"
@ONLY
)
endif()
set_property(TARGET ${MLN_QT_QML_PLUGIN} PROPERTY EXPORT_NAME PluginQml)

Expand Down Expand Up @@ -140,10 +167,10 @@ install(
DESTINATION "qml/QtLocation/MapLibre"
)

if (COMMAND qt_add_qml_module)
if(COMMAND qt_add_qml_module)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/${MLN_QT_QML_PLUGIN}.qmltypes"
DESTINATION "qml/QtLocation/MapLibre"
)
)
endif()
6 changes: 3 additions & 3 deletions src/widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ set_target_properties(
)

# Qt MOC
if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool)
if(Qt6_FOUND AND COMMAND qt_enable_autogen_tool)
qt_enable_autogen_tool(Widgets "moc" ON)
endif()

Expand Down Expand Up @@ -73,7 +73,7 @@ target_link_libraries(
$<BUILD_INTERFACE:mbgl-compiler-options>
$<BUILD_INTERFACE:CompilerOptions>
)
if (Qt6_FOUND)
if(Qt6_FOUND)
target_link_libraries(
Widgets
PUBLIC
Expand All @@ -88,7 +88,7 @@ else()
endif()

# Apple specifics
if (APPLE)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(
Widgets
PROPERTIES
Expand Down
10 changes: 7 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
if(
CMAKE_SYSTEM_NAME STREQUAL "Android"
OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten"
OR CMAKE_SYSTEM_NAME STREQUAL "iOS"
)
return()
endif()

add_subdirectory(core)
if (MLN_QT_WITH_LOCATION)
if(MLN_QT_WITH_LOCATION)
add_subdirectory(qml)
endif()
if (MLN_QT_WITH_WIDGETS)
if(MLN_QT_WITH_WIDGETS)
add_subdirectory(widgets)
endif()
9 changes: 6 additions & 3 deletions test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (Qt5_FOUND)
if(Qt5_FOUND)
return()
endif()

Expand All @@ -7,7 +7,7 @@ set(test_sources
map_tester.cpp map_tester.hpp
test_core.cpp
)
if (COMMAND qt_add_executable)
if(COMMAND qt_add_executable)
qt_add_executable(test_mln_core ${test_sources})
else()
add_executable(test_mln_core ${test_sources})
Expand Down Expand Up @@ -36,7 +36,10 @@ if(MLN_QT_WITH_CLANG_TIDY)
set_target_properties(test_mln_core PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
endif()

add_test(NAME test_mln_core COMMAND $<TARGET_FILE:test_mln_core>)
add_test(
NAME test_mln_core
COMMAND $<TARGET_FILE:test_mln_core>
)
set_tests_properties(
test_mln_core
PROPERTIES
Expand Down
10 changes: 7 additions & 3 deletions test/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
if (COMMAND qt_add_executable)
if(COMMAND qt_add_executable)
qt_add_executable(test_mln_qml test_qml.cpp)
else()
add_executable(test_mln_qml test_qml.cpp)
endif()

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS QuickTest REQUIRED)
target_link_libraries(test_mln_qml
target_link_libraries(
test_mln_qml
PRIVATE
Qt${QT_VERSION_MAJOR}::QuickTest
$<BUILD_INTERFACE:mbgl-compiler-options>
Expand All @@ -15,7 +16,10 @@ if(MLN_QT_WITH_CLANG_TIDY)
set_target_properties(test_mln_qml PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
endif()

add_test(NAME test_mln_qml COMMAND $<TARGET_FILE:test_mln_qml> -input ${CMAKE_CURRENT_SOURCE_DIR}/qt${QT_VERSION_MAJOR})
add_test(
NAME test_mln_qml
COMMAND $<TARGET_FILE:test_mln_qml> -input ${CMAKE_CURRENT_SOURCE_DIR}/qt${QT_VERSION_MAJOR}
)
set_tests_properties(
test_mln_qml
PROPERTIES
Expand Down
7 changes: 5 additions & 2 deletions test/widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(test_sources
gl_tester.cpp gl_tester.hpp
test_widgets.cpp
)
if (COMMAND qt_add_executable)
if(COMMAND qt_add_executable)
qt_add_executable(test_mln_widgets ${test_sources})
else()
add_executable(test_mln_widgets ${test_sources})
Expand Down Expand Up @@ -33,4 +33,7 @@ if(MLN_QT_WITH_CLANG_TIDY)
set_target_properties(test_mln_widgets PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
endif()

add_test(NAME test_mln_widgets COMMAND $<TARGET_FILE:test_mln_widgets>)
add_test(
NAME test_mln_widgets
COMMAND $<TARGET_FILE:test_mln_widgets>
)

0 comments on commit a1808ad

Please sign in to comment.