Skip to content

Commit

Permalink
Devendor some thridparty deps (organicmaps#7836)
Browse files Browse the repository at this point in the history
* Link with Qt6::Network on windows
* Make find_program(BASH) REQUIRED to prevent build-time errors
* Link more targets explicitly to pickup transitive dependencies
* Don't add unsupported flags on MSVC
  Drive-by: use add_compile_options instead of add_definitions to set -fno-omit-frame-pointer
* Move find_package(gflags) out of 3party
  GLOBAL flag for find_package has been added in CMake 3.24
* Don't hardcode paths to 3party/utfcpp
* Use system expat explicitly if needed
* Use system jansson explicitly if needed
* Use find_package(ZLIB) to find zlib
* Don't use vendored Freetype, ICU and HarfBuzz when WITH_SYSTEM_PROVIDED_3PARTY is set
* Find pugixml explicitly
* Fix typo in target name
* Update utfcpp include path
* Let CMake handle /DEBUG flag for MSVC

Signed-off-by: Osyotr <[email protected]>
  • Loading branch information
Osyotr authored Apr 6, 2024
1 parent edb7fc2 commit 76dd632
Show file tree
Hide file tree
Showing 28 changed files with 103 additions and 43 deletions.
24 changes: 13 additions & 11 deletions 3party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# Compatibility with CMake < 3.5 will be removed from a future version of CMake.
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)

if (WITH_SYSTEM_PROVIDED_3PARTY)
set(GFLAGS_USE_TARGET_NAMESPACE ON)
find_package(gflags REQUIRED GLOBAL)
else()
if (NOT WITH_SYSTEM_PROVIDED_3PARTY)
# Suppress "Policy CMP0077 is not set: option() honors normal variables"
# for the freetype, expat and jansson options.
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
Expand All @@ -25,6 +22,7 @@ else()
set(EXPAT_DTD OFF)
set(EXPAT_NS ON)
add_subdirectory(expat/expat)
add_library(expat::expat ALIAS expat)

# Configure Jansson library.
set(JANSSON_BUILD_DOCS OFF)
Expand All @@ -34,6 +32,7 @@ else()
set(JANSSON_WITHOUT_TESTS ON)
add_subdirectory(jansson/jansson/)
target_include_directories(jansson INTERFACE "${PROJECT_BINARY_DIR}/3party/jansson/jansson/include")
add_library(jansson::jansson ALIAS jansson)

# Add gflags library.
add_subdirectory(gflags)
Expand All @@ -44,17 +43,20 @@ else()

# Add protobuf library.
add_subdirectory(protobuf)
endif()

add_subdirectory(agg)
add_subdirectory(bsdiff-courgette)
if (NOT PLATFORM_LINUX)
add_subdirectory(freetype)
add_subdirectory(icu)
add_subdirectory(harfbuzz)
endif()

if (NOT PLATFORM_LINUX)
add_subdirectory(freetype)
add_subdirectory(icu)
add_subdirectory(harfbuzz)
add_library(utf8cpp INTERFACE)
add_library(utf8cpp::utf8cpp ALIAS utf8cpp)
target_include_directories(utf8cpp INTERFACE "${OMIM_ROOT}/3party/utfcpp/source")
endif()

add_subdirectory(agg)
add_subdirectory(bsdiff-courgette)
add_subdirectory(liboauthcpp)
add_subdirectory(minizip)
add_subdirectory(open-location-code)
Expand Down
1 change: 0 additions & 1 deletion 3party/utf8cpp/include/utf8cpp

This file was deleted.

35 changes: 26 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ if (NOT CMAKE_BUILD_TYPE)
endif()

# Global compile options for all configurations.
add_compile_options(-ffast-math)
if (MSVC)
add_compile_options(/utf-8)
add_link_options(/INCREMENTAL:NO)
else()
add_compile_options(-ffast-math)
endif()

if (PLATFORM_WIN)
add_definitions(
Expand All @@ -114,10 +119,15 @@ endif()

# Built-in CMake configurations: Debug, Release, RelWithDebInfo, MinSizeRel
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DDEBUG -fno-omit-frame-pointer)
add_definitions(-DDEBUG)
if (NOT MSVC)
add_compile_options(-fno-omit-frame-pointer)
endif()
elseif (${CMAKE_BUILD_TYPE} MATCHES "Rel")
add_definitions(-DRELEASE)
add_compile_options(-Ofast) # Also enables -ffast-math
if (NOT MSVC)
add_compile_options(-Ofast) # Also enables -ffast-math
endif()
else()
message(FATAL_ERROR "Unknown build type: " ${CMAKE_BUILD_TYPE})
endif()
Expand Down Expand Up @@ -262,11 +272,6 @@ if (NOT PLATFORM_IPHONE AND NOT PLATFORM_ANDROID)
find_package(Qt6 COMPONENTS REQUIRED ${qt_components} PATHS $ENV{QT_PATH} /opt/homebrew/opt/qt@6 /usr/local/opt/qt@6 /usr/lib/x86_64-linux-gnu/qt6)
endif()

find_library(LIBZ NAMES z)
if (LIBZ STREQUAL "LIBZ-NOTFOUND")
message(FATAL_ERROR "Failed to find libz library.")
endif()

# To allow #include "base/file_name.hpp" in all sources.
include_directories(${CMAKE_HOME_DIRECTORY})

Expand Down Expand Up @@ -302,12 +307,24 @@ if (USE_PCH)
endif()

# Should be on the root level, not in 3party, so tests can get these dependencies.
if (PLATFORM_LINUX)
if (PLATFORM_LINUX OR PLATFORM_WIN)
find_package(ICU COMPONENTS uc i18n data REQUIRED)
find_package(Freetype REQUIRED)
find_package(harfbuzz REQUIRED)
endif()

if (WITH_SYSTEM_PROVIDED_3PARTY)
set(GFLAGS_USE_TARGET_NAMESPACE ON)
find_package(gflags REQUIRED)

find_package(expat CONFIG REQUIRED)
find_package(jansson CONFIG REQUIRED)
find_package(pugixml REQUIRED)
find_package(utf8cpp REQUIRED)
endif()

find_package(ZLIB REQUIRED)

# Include 3party dependencies.
add_subdirectory(3party)

Expand Down
1 change: 1 addition & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ omim_add_library(${PROJECT_NAME} ${SRC})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE Threads::Threads)
target_link_libraries(${PROJECT_NAME} PUBLIC utf8cpp::utf8cpp)

if (NOT WITH_SYSTEM_PROVIDED_3PARTY)
target_include_directories(${PROJECT_NAME} PRIVATE "${OMIM_ROOT}/3party/fast_double_parser/include")
Expand Down
2 changes: 1 addition & 1 deletion base/internal/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "std/target_os.hpp"

#include <utf8cpp/utf8/unchecked.h>
#include <utf8/unchecked.h>

std::string DebugPrint(std::string const & t)
{
Expand Down
2 changes: 1 addition & 1 deletion base/string_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string_view>
#include <type_traits>

#include <utf8cpp/utf8/unchecked.h>
#include <utf8/unchecked.h>

/// All methods work with strings in utf-8 format
namespace strings
Expand Down
2 changes: 1 addition & 1 deletion cmake/OmimConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set(OMIM_WARNING_FLAGS
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unused-parameter> # We have a lot of functions with unused parameters
)
set(3PARTY_INCLUDE_DIRS "${OMIM_ROOT}/3party/boost" "${OMIM_ROOT}/3party/utf8cpp/include")
set(3PARTY_INCLUDE_DIRS "${OMIM_ROOT}/3party/boost")
set(OMIM_DATA_DIR "${OMIM_ROOT}/data")
set(OMIM_USER_RESOURCES_DIR "${OMIM_ROOT}/data")
4 changes: 2 additions & 2 deletions coding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ omim_add_library(${PROJECT_NAME} ${SRC})

target_link_libraries(${PROJECT_NAME}
base
expat
expat::expat
cppjansson
succinct
ICU::uc
ICU::i18n # For transliteration.
oauthcpp # For base64_encode and base64_decode
minizip
${LIBZ}
ZLIB::ZLIB
)

omim_add_test_subdirectory(coding_tests)
2 changes: 1 addition & 1 deletion coding/coding_tests/string_utf8_multilang_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "base/control_flow.hpp"

#include <utf8cpp/utf8.h>
#include <utf8.h>

#include <cstddef>
#include <string>
Expand Down
2 changes: 2 additions & 0 deletions coding/internal/xmlparser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <sstream>
#include <string>

#ifndef XML_STATIC
#define XML_STATIC
#endif
#include <expat.h>

#if defined(__clang__)
Expand Down
4 changes: 3 additions & 1 deletion cppjansson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ set(SRC
)
omim_add_library(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME}
jansson
PUBLIC
base
jansson::jansson
)
2 changes: 1 addition & 1 deletion drape/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ target_link_libraries(${PROJECT_NAME}
sdf_image
harfbuzz
ICU::i18n
expat
expat::expat
$<$<BOOL:${PLATFORM_MAC}>:-framework\ OpenGL>
$<$<BOOL:${PLATFORM_LINUX}>:OpenGL::GL>
)
Expand Down
8 changes: 8 additions & 0 deletions ge0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ set(SRC
)

omim_add_library(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME}
PUBLIC
coding

PRIVATE
base
geometry
)

omim_add_test_subdirectory(ge0_tests)
2 changes: 1 addition & 1 deletion generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ target_link_libraries(${PROJECT_NAME}
descriptions
indexer
cppjansson
expat
expat::expat
tess2
$<$<BOOL:CMAKE_DL_LIBS>:${CMAKE_DL_LIBS}> # dladdr from boost::stacktrace
)
Expand Down
4 changes: 2 additions & 2 deletions generator/pygen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ omim_link_libraries(
base
opening_hours
freetype
expat
expat::expat
ICU::i18n
cppjansson
protobuf
Expand All @@ -40,7 +40,7 @@ omim_link_libraries(
oauthcpp
sqlite3
${CMAKE_DL_LIBS}
${LIBZ}
ZLIB::ZLIB
${Boost_LIBRARIES}
)

Expand Down
2 changes: 1 addition & 1 deletion indexer/search_string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <queue>
#include <vector>

#include <utf8cpp/utf8/unchecked.h>
#include <utf8/unchecked.h>

namespace search
{
Expand Down
2 changes: 1 addition & 1 deletion kml/pykmlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ omim_link_libraries(
oauthcpp
protobuf
pugixml
expat
expat::expat
succinct
)

Expand Down
5 changes: 3 additions & 2 deletions platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ elseif(${PLATFORM_ANDROID})
)
else() # neither iPhone nor Android
# Find bash first, on Windows it can be either in Git or in WSL
find_program(BASH bash)
find_program(BASH bash REQUIRED)
# Generate version header file.
execute_process(COMMAND "${BASH}" tools/unix/version.sh qt_version
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
Expand Down Expand Up @@ -183,7 +183,7 @@ if (APPLE)
target_compile_options(${PROJECT_NAME} PRIVATE "-fobjc-arc")
endif()

if (PLATFORM_LINUX)
if (PLATFORM_LINUX OR PLATFORM_WIN)
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC ON)
endif()

Expand All @@ -192,6 +192,7 @@ target_link_libraries(${PROJECT_NAME}
coding
$<$<BOOL:${PLATFORM_DESKTOP}>:Qt6::Core>
$<$<BOOL:${PLATFORM_LINUX}>:Qt6::Network>
$<$<BOOL:${PLATFORM_WIN}>:Qt6::Network>
$<$<BOOL:${QT_POSITIONING}>:Qt6::Positioning>
$<$<BOOL:${PLATFORM_MAC}>:
-framework\ Foundation
Expand Down
1 change: 1 addition & 0 deletions routing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ set(SRC
omim_add_library(${PROJECT_NAME} ${SRC})

target_link_libraries(${PROJECT_NAME}
base
routing_common
platform
traffic
Expand Down
5 changes: 4 additions & 1 deletion routing/routing_quality/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ set(SRC
omim_add_library(${PROJECT_NAME} ${SRC})

target_link_libraries(${PROJECT_NAME}
jansson # serdes_json.hpp is in coding
PUBLIC
coding
geometry
routing
)
6 changes: 6 additions & 0 deletions routing_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ set(SRC
)

omim_add_library(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME}
PUBLIC
base
indexer
platform
)

omim_add_test_subdirectory(routing_common_tests)
2 changes: 1 addition & 1 deletion search/pysearch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ omim_link_libraries(
pugixml
succinct
${Boost_LIBRARIES}
${LIBZ}
ZLIB::ZLIB
)

link_qt5_core(${PROJECT_NAME})
Expand Down
2 changes: 1 addition & 1 deletion shaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ if (PLATFORM_IPHONE)
endif()

# Do not include glm's CMakeLists.txt, because it's outdated and not necessary.
target_include_directories(${PROJECT_NAME} PUBLIC ${OMIM_ROOT}/3party/glm ${OMIM_ROOT}/3party/utf8cpp/include)
target_include_directories(${PROJECT_NAME} PUBLIC "${OMIM_ROOT}/3party/glm")

target_link_libraries(${PROJECT_NAME} drape)

Expand Down
2 changes: 1 addition & 1 deletion track_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ target_link_libraries(${PROJECT_NAME}
routing
kml
coding
expat
expat::expat
gflags::gflags
)
11 changes: 11 additions & 0 deletions tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ set(
)

omim_add_library(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME}
PUBLIC
routing
traffic

PRIVATE
base
coding
geometry
platform
)

omim_add_test_subdirectory(tracking_tests)

Expand Down
2 changes: 1 addition & 1 deletion traffic/pytraffic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ omim_link_libraries(
succinct
ICU::i18n
${Boost_LIBRARIES}
${LIBZ}
ZLIB::ZLIB
)

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
Loading

0 comments on commit 76dd632

Please sign in to comment.