Skip to content

Commit

Permalink
[qt] Improve CMake setup (maplibre#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej authored Oct 19, 2021
1 parent cae0fc2 commit 66f3210
Show file tree
Hide file tree
Showing 8 changed files with 1,110 additions and 199 deletions.
47 changes: 25 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

option(MBGL_WITH_CORE_ONLY "Build only the core bits, no platform code" OFF)
option(MBGL_WITH_COVERAGE "Enable code coverage collection" OFF)
option(MBGL_WITH_QT "Build Mapbox GL Qt bindings" OFF)
option(MBGL_WITH_SANITIZER "Use [address|thread|undefined] here" OFF)
option(MBGL_WITH_RTTI "Compile with runtime type information" OFF)
option(MBGL_WITH_OPENGL "Build with OpenGL renderer" ON)
option(MBGL_WITH_EGL "Build with EGL renderer" OFF)
option(MBGL_WITH_WERROR "Make all compilation warnings errors" ON)

if (MBGL_WITH_QT)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
endif()

project("Mapbox GL Native" LANGUAGES CXX C)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand All @@ -15,15 +29,6 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

option(MBGL_WITH_CORE_ONLY "Build only the core bits, no platform code" OFF)
option(MBGL_WITH_COVERAGE "Enable code coverage collection" OFF)
option(MBGL_WITH_QT "Build Mapbox GL Qt bindings" OFF)
option(MBGL_WITH_SANITIZER "Use [address|thread|undefined] here" OFF)
option(MBGL_WITH_RTTI "Compile with runtime type information" OFF)
option(MBGL_WITH_OPENGL "Build with OpenGL renderer" ON)
option(MBGL_WITH_EGL "Build with EGL renderer" OFF)
option(MBGL_WITH_WERROR "Make all compilation warnings errors" ON)

add_library(
mbgl-compiler-options INTERFACE
)
Expand All @@ -49,7 +54,7 @@ target_compile_options(
-fsanitize-blacklist=${UBSAN_BLACKLIST}>
$<$<STREQUAL:${MBGL_WITH_SANITIZER},undefined>:-fsanitize=float-divide-by-zero,
-fsanitize-blacklist=${UBSAN_BLACKLIST}>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<BOOL:${MBGL_WITH_RTTI}>>>:-fno-rtti>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<OR:$<BOOL:${MBGL_WITH_RTTI}>,$<CXX_COMPILER_ID:MSVC>>>>:-fno-rtti>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wall>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wshadow>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wextra>
Expand All @@ -58,9 +63,15 @@ target_compile_options(
$<$<CXX_COMPILER_ID:GNU>:-Wno-error=maybe-uninitialized>
$<$<CXX_COMPILER_ID:GNU>:-Wno-error=return-type>
$<$<CXX_COMPILER_ID:GNU>:-Wno-error=unknown-pragmas>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-error=deprecated-declarations>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-error=unused-parameter>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-error=unused-property-ivar>
$<$<AND:$<CXX_COMPILER_ID:AppleClang>,$<NOT:$<BOOL:${MBGL_WITH_QT}>>>:-Wno-error=deprecated-declarations>
$<$<AND:$<CXX_COMPILER_ID:AppleClang>,$<NOT:$<BOOL:${MBGL_WITH_QT}>>>:-Wno-error=unused-parameter>
$<$<AND:$<CXX_COMPILER_ID:AppleClang>,$<NOT:$<BOOL:${MBGL_WITH_QT}>>>:-Wno-error=unused-property-ivar>
$<$<CXX_COMPILER_ID:MSVC>:/utf-8>
# $<$<CXX_COMPILER_ID:MSVC>:/WX> # all warnings as errors
$<$<CXX_COMPILER_ID:MSVC>:/wd4068> # pragma
$<$<CXX_COMPILER_ID:MSVC>:/wd4244> # types
$<$<CXX_COMPILER_ID:MSVC>:/wd4828> # encoding
$<$<CXX_COMPILER_ID:MSVC>:/D_CRT_SECURE_NO_WARNINGS>
)

target_link_libraries(
Expand All @@ -86,14 +97,6 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

if(MBGL_WITH_QT)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
endif()

add_library(
mbgl-core STATIC
${PROJECT_SOURCE_DIR}/include/mbgl/actor/actor.hpp
Expand Down Expand Up @@ -829,7 +832,7 @@ add_library(
)

if(MBGL_WITH_OPENGL)
message("-- Configuring GL-Native with OpenGL renderer backend")
message(STATUS "Configuring GL-Native with OpenGL renderer backend")
target_compile_definitions(
mbgl-core
PRIVATE MBGL_RENDER_BACKEND_OPENGL=1
Expand Down
2 changes: 1 addition & 1 deletion platform/ios/ios-test-runners.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if(MBGL_IOS_RENDER_TEST)
initialize_ios_target(mbgl-vendor-zip-archive)

if(MBGL_WITH_OPENGL)
message("-- Setting up test data for iOS render test with OpenGL renderer")
message(STATUS "Setting up test data for iOS render test with OpenGL renderer")
set(PREPARE_CMD "${PROJECT_SOURCE_DIR}/render-test/ios/setup_test_data.sh")
endif()
add_custom_target(RenderTestApp-prepare COMMAND ${PREPARE_CMD} ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
Expand Down
Loading

0 comments on commit 66f3210

Please sign in to comment.