Skip to content

Commit

Permalink
Use less generic target names to allow usage as subproject (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej authored Apr 26, 2024
1 parent a5a8385 commit c7fbde1
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 80 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ elseif(MSVC OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
endif()

# Common configuration
add_library(CompilerOptions INTERFACE)
add_library(MLNQtCompilerOptions INTERFACE)
target_compile_options(
CompilerOptions
MLNQtCompilerOptions
INTERFACE
$<$<BOOL:${MLN_QT_WITH_COVERAGE}>:--coverage>
)
target_link_libraries(
CompilerOptions
MLNQtCompilerOptions
INTERFACE
$<$<BOOL:${MLN_QT_WITH_COVERAGE}>:--coverage>
)
Expand Down
51 changes: 26 additions & 25 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ add_subdirectory(

# Public headers
string(TOLOWER ${MLN_QT_NAME} MLN_QT_NAME_LOWERCASE)
set(Core_Headers
set(MLNQtCore_Headers
export_core.hpp
map.hpp
settings.hpp
Expand All @@ -28,34 +28,34 @@ set(Core_Headers
)
# Header generation
mln_umbrella_header_preprocess(${MLN_QT_NAME_LOWERCASE} ${MLN_QT_NAME} HeaderOut)
list(APPEND Core_Headers_Generated ${HeaderOut})
foreach(Header ${Core_Headers})
list(APPEND MLNQtCore_Headers_Generated ${HeaderOut})
foreach(Header ${MLNQtCore_Headers})
mln_header_preprocess(${Header} ${MLN_QT_NAME} HeaderOut)
list(APPEND Core_Headers_Generated ${HeaderOut})
list(APPEND MLNQtCore_Headers_Generated ${HeaderOut})
endforeach()
set(Core_Headers ${MLN_QT_NAME_LOWERCASE}.hpp ${Core_Headers} ${Core_Headers_Generated})
set(MLNQtCore_Headers ${MLN_QT_NAME_LOWERCASE}.hpp ${MLNQtCore_Headers} ${MLNQtCore_Headers_Generated})

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

# Main sources
target_sources(
Core
MLNQtCore
PRIVATE
${Core_Headers}
${MLNQtCore_Headers}
conversion_p.hpp
geojson.cpp geojson_p.hpp
map_observer.cpp map_observer_p.hpp
Expand All @@ -80,30 +80,31 @@ target_sources(

# Linux/Mac: Set framework, version and headers
set_target_properties(
Core
MLNQtCore
PROPERTIES
AUTOMOC ON
OUTPUT_NAME ${MLN_QT_NAME}
EXPORT_NAME Core
VERSION ${MLN_QT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${Core_Headers}"
PUBLIC_HEADER "${MLNQtCore_Headers}"
)

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

# Common compile definitions
target_compile_definitions(
Core
MLNQtCore
PRIVATE
QT_BUILD_MAPLIBRE_CORE_LIB
)

# Common include directories
target_include_directories(
Core
MLNQtCore
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand All @@ -118,26 +119,26 @@ target_include_directories(

# Common link libraries
target_link_libraries(
Core
MLNQtCore
PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Network
PRIVATE
$<BUILD_INTERFACE:mbgl-compiler-options>
$<BUILD_INTERFACE:mbgl-core>
$<BUILD_INTERFACE:CompilerOptions>
$<BUILD_INTERFACE:MLNQtCompilerOptions>
)
if(NOT MLN_QT_WITH_INTERNAL_SQLITE)
target_link_libraries(
Core
MLNQtCore
PUBLIC
Qt${QT_VERSION_MAJOR}::Sql
)
endif()
foreach(target ${MLN_QT_VENDOR_LIBRARIES})
target_link_libraries(
Core
MLNQtCore
PRIVATE
$<BUILD_INTERFACE:${target}>
)
Expand All @@ -146,7 +147,7 @@ endforeach()
# Apple specifics
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(
Core
MLNQtCore
PROPERTIES
FRAMEWORK ON
FRAMEWORK_VERSION A
Expand All @@ -155,15 +156,15 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION}
)
target_include_directories(
Core
MLNQtCore
INTERFACE
$<INSTALL_INTERFACE:lib/${MLN_QT_NAME}.framework>
)
endif()

# Development specifics
if(MLN_QT_WITH_CLANG_TIDY)
set_target_properties(Core PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
set_target_properties(MLNQtCore PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
endif()

# Export and installation
Expand All @@ -179,7 +180,7 @@ install(
)

install(
TARGETS Core
TARGETS MLNQtCore
EXPORT ${MLN_QT_NAME}CoreTargets
# Explicit set of DESTINATION is needed for older CMake versions.
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
Expand Down
35 changes: 18 additions & 17 deletions src/location/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Make a Qt library
if(COMMAND qt_add_library)
if(MLN_QT_STATIC)
qt_add_library(Location STATIC)
qt_add_library(MLNQtLocation STATIC)
else()
qt_add_library(Location)
qt_add_library(MLNQtLocation)
endif()
else()
if(MLN_QT_STATIC)
add_library(Location STATIC)
add_library(MLNQtLocation STATIC)
else()
add_library(Location SHARED)
add_library(MLNQtLocation SHARED)
endif()
endif()
add_library(${MLN_QT_NAME}::Location ALIAS Location)
add_library(${MLN_QT_NAME}::Location ALIAS MLNQtLocation)

target_sources(
Location
MLNQtLocation
PRIVATE
qgeomap.cpp qgeomap.hpp qgeomap_p.hpp
qt_mapping_engine.cpp qt_mapping_engine.hpp
Expand All @@ -27,29 +27,30 @@ target_sources(

# Linux/Mac: Set framework, version and headers
set_target_properties(
Location
MLNQtLocation
PROPERTIES
AUTOMOC ON
OUTPUT_NAME ${MLN_QT_NAME}Location
EXPORT_NAME Location
VERSION ${MLN_QT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

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

# Common compile definitions
target_compile_definitions(
Location
MLNQtLocation
PRIVATE
QT_BUILD_MAPLIBRE_LOCATION_LIB
)

# Common include directories
target_include_directories(
Location
MLNQtLocation
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/include
Expand All @@ -60,21 +61,21 @@ target_include_directories(

# Common link libraries
target_link_libraries(
Location
MLNQtLocation
PUBLIC
Core
MLNQtCore
PRIVATE
$<$<BOOL:${Qt6_FOUND}>:Qt${QT_VERSION_MAJOR}::OpenGL>
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::LocationPrivate
$<BUILD_INTERFACE:mbgl-compiler-options>
$<BUILD_INTERFACE:CompilerOptions>
$<BUILD_INTERFACE:MLNQtCompilerOptions>
)

# Apple specifics
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(
Location
MLNQtLocation
PROPERTIES
FRAMEWORK ON
FRAMEWORK_VERSION A
Expand All @@ -83,15 +84,15 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION}
)
target_include_directories(
Location
MLNQtLocation
INTERFACE
$<INSTALL_INTERFACE:lib/${MLN_QT_NAME}Location.framework>
)
endif()

# Development specifics
if(MLN_QT_WITH_CLANG_TIDY)
set_target_properties(Location PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
set_target_properties(MLNQtLocation PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
endif()

# Export and installation
Expand All @@ -102,7 +103,7 @@ install(
)

install(
TARGETS Location
TARGETS MLNQtLocation
EXPORT ${MLN_QT_NAME}LocationTargets
# Explicit set of DESTINATION is needed for older CMake versions.
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
Expand Down
8 changes: 4 additions & 4 deletions src/location/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ target_include_directories(
target_link_libraries(
${MLN_QT_GEOSERVICES_PLUGIN}
PRIVATE
Location
MLNQtLocation
Qt${QT_VERSION_MAJOR}::Location
Qt${QT_VERSION_MAJOR}::LocationPrivate
$<BUILD_INTERFACE:mbgl-compiler-options>
$<BUILD_INTERFACE:CompilerOptions>
$<BUILD_INTERFACE:MLNQtCompilerOptions>
)

# QtLocation plugin development specifics
Expand Down Expand Up @@ -192,10 +192,10 @@ target_include_directories(
target_link_libraries(
${MLN_QT_QML_PLUGIN}
PRIVATE
Location
MLNQtLocation
Qt${QT_VERSION_MAJOR}::LocationPrivate
$<BUILD_INTERFACE:mbgl-compiler-options>
$<BUILD_INTERFACE:CompilerOptions>
$<BUILD_INTERFACE:MLNQtCompilerOptions>
)

# QtLocation QML extenstion plugin development specifics
Expand Down
Loading

0 comments on commit c7fbde1

Please sign in to comment.