Skip to content

Commit

Permalink
cleanup cmake project
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Aug 7, 2024
1 parent 03b984b commit 9f31a58
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 221 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build_android_arm64_ndk22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/22.1.7171670/build/cmake/android.toolchain.cmake
-DCMAKE_MAKE_PROGRAM=${ANDROID_HOME}/ndk/22.1.7171670/prebuilt/linux-x86_64/bin/make
-DANDROID_ABI=arm64-v8a
-DANDROID_STL_PREFIX=llvm-libc++
-DANDROID_STL_SHARED_LIBRARIES=c++_shared
-DANDROID_SDK_MINVER=24
-DANDROID_SDK_TARGET=26
-DANDROID_NATIVE_API_LEVEL=24
-DQT_ANDROID_PLATFORM_LEVEL=29
-DQT_ANDROID_SDK_BUILDTOOLS_REVISION=29.0.2
-DQT_ANDROID_TOOL_PREFIX=aarch64-linux-android
-DQT_ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}
-DQT_ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/22.1.7171670
-DQT_ANDROID_QT_ROOT=${Qt5_DIR}
-DQt5_DIR=${Qt5_DIR}/lib/cmake/Qt5
-DQt5Core_DIR=${Qt5_DIR}/lib/cmake/Qt5Core
-DQt5Gui_DIR=${Qt5_DIR}/lib/cmake/Qt5Gui
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/build_android_x64_ndk22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,13 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/22.1.7171670/build/cmake/android.toolchain.cmake
-DCMAKE_MAKE_PROGRAM=${ANDROID_HOME}/ndk/22.1.7171670/prebuilt/linux-x86_64/bin/make
-DANDROID_ABI=x86_64
-DANDROID_STL_PREFIX=llvm-libc++
-DANDROID_STL_SHARED_LIBRARIES=c++_shared
-DANDROID_SDK_MINVER=24
-DANDROID_SDK_TARGET=26
-DANDROID_NATIVE_API_LEVEL=24
-DQT_ANDROID_PLATFORM_LEVEL=29
-DQT_ANDROID_SDK_BUILDTOOLS_REVISION=29.0.2
-DQT_ANDROID_TOOL_PREFIX=x86_64-linux-android
-DQT_ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}
-DQT_ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/22.1.7171670
-DQT_ANDROID_QT_ROOT=${Qt5_DIR}
-DQt5_DIR=${Qt5_DIR}/lib/cmake/Qt5
-DQt5Core_DIR=${Qt5_DIR}/lib/cmake/Qt5Core
-DQt5Gui_DIR=${Qt5_DIR}/lib/cmake/Qt5Gui
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/build_android_x86_ndk22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_HOME}/ndk/22.1.7171670/build/cmake/android.toolchain.cmake
-DCMAKE_MAKE_PROGRAM=${ANDROID_HOME}/ndk/22.1.7171670/prebuilt/linux-x86_64/bin/make
-DANDROID_ABI=x86
-DANDROID_STL_PREFIX=llvm-libc++
-DANDROID_STL_SHARED_LIBRARIES=c++_shared
-DANDROID_SDK_MINVER=24
-DANDROID_SDK_TARGET=26
-DANDROID_NATIVE_API_LEVEL=24
-DQT_ANDROID_PLATFORM_LEVEL=29
-DQT_ANDROID_SDK_BUILDTOOLS_REVISION=29.0.2
-DQT_ANDROID_TOOL_PREFIX=i686-linux-android
-DQT_ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}
-DQT_ANDROID_NDK_ROOT=${ANDROID_HOME}/ndk/22.1.7171670
-DQT_ANDROID_QT_ROOT=${Qt5_DIR}
-DQt5_DIR=${Qt5_DIR}/lib/cmake/Qt5
-DQt5Core_DIR=${Qt5_DIR}/lib/cmake/Qt5Core
-DQt5Gui_DIR=${Qt5_DIR}/lib/cmake/Qt5Gui
Expand Down
110 changes: 50 additions & 60 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,28 @@ else()
set(CMAKE_IGNORE_PATH "/opt/local/bin;/opt/local/include;/opt/local/lib")
endif()

# Workaround for QTBUG-87863 before calling add_subirectory
find_package(Qt5 COMPONENTS Core REQUIRED)
set(QT_VERSION_PREFERRED "5" CACHE STRING "preferred Qt version" FORCE)
include(qtchooser)
if(NOT QT_FOUND)
message(FATAL_ERROR "Qt${QT_VERSION_PREFERRED} NOT found")
elseif(Qt5Core_VERSION VERSION_LESS 5.15.2)
message(FATAL_ERROR "Qt version not supported")
endif()

add_subdirectory(backend)

set(CMAKE_AUTOMOC ON)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Qml REQUIRED)
find_package(Qt5Quick REQUIRED)

set(QT_MIN_VERSION 5.15.0)
find_package(Qt5QuickControls2 ${QT_MIN_VERSION} REQUIRED)
find_package(Qt5 ${QT_VERSION} COMPONENTS
Core Gui Qml Quick QuickControls2 Widgets Xml Svg Network Sensors
Multimedia RemoteObjects Positioning REQUIRED)
if(UNIX AND NOT APPLE)
find_library(DBUS_LIBRARIES dbus-1)
if(DBUS_LIBRARIES)
find_package(Qt5 ${QT_VERSION} COMPONENTS DBus REQUIRED)
set(HAVE_DBUS 1)
message(STATUS "Enable DBus interfaces")
endif()
endif()

if(ANDROID)
find_package(Qt5AndroidExtras REQUIRED)
Expand All @@ -119,15 +128,6 @@ elseif(UNIX AND NOT APPLE)
endif()
endif()

find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Sensors REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5RemoteObjects REQUIRED)
find_package(Qt5Positioning REQUIRED)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)

Expand Down Expand Up @@ -180,17 +180,13 @@ if(UNIX)
endif()

add_definitions(-DAPP_VERSION="${APP_VERSION}")
add_definitions(-DQT_STATICPLUGIN)

if(Qt5Core_VERSION VERSION_LESS 5.15.2)
message(FATAL_ERROR "Qt version not supported")
else()
qt5_add_resources(osmin-resources gui/osmin_controls2_515.qrc)
endif()
include_directories(${PROJECT_BINARY_DIR} ${LIBOSMSCOUT_INCLUDE_DIRS})

qt5_generate_repc(osmin_SOURCES src/servicemessenger.rep SOURCE)
qt5_generate_repc(osmin_SOURCES src/servicemessenger.rep REPLICA)

include_directories(${PROJECT_BINARY_DIR} ${LIBOSMSCOUT_INCLUDE_DIRS})
qt5_add_resources(osmin-resources gui/osmin_controls2_515.qrc)

if(ANDROID)
add_library(osmin SHARED ${osmin_SOURCES} ${osmin_HEADERS} ${osmin-resources})
Expand All @@ -199,32 +195,21 @@ else()
endif()

target_link_libraries(osmin PRIVATE ${LIBOSMSCOUT_LIBRARIES})

add_definitions(-DQT_STATICPLUGIN)
target_link_libraries(osmin PRIVATE
Qt5::QuickControls2 Qt5::RemoteObjects Qt5::Positioning
Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg
Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core)

if(ANDROID)
add_definitions(-DDEVICE_MOBILE)
add_definitions(-frtti) # dynamic_cast: https://github.com/android/ndk/issues/519
target_link_libraries(osmin PRIVATE Qt5::QuickControls2 Qt5::AndroidExtras android log Qt5::RemoteObjects Qt5::Positioning
Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core)
else()
if(BUILD_DEVICE_MOBILE)
add_definitions(-DDEVICE_MOBILE)
endif()
target_link_libraries(osmin PRIVATE Qt5::QuickControls2 Qt5::RemoteObjects Qt5::Positioning
Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core)
if(HAVE_DBUS)
add_definitions(-DHAVE_DBUS)
target_link_libraries(osmin PRIVATE Qt5::DBus)
endif()
endif()

if(ANDROID)
target_link_libraries(osmin PRIVATE Qt5::AndroidExtras android log)
# Fix import of shared omp with android ndk rev 21
if(OpenMP_CXX_LIBRARIES MATCHES libomp.so)
set(SHARED_LIBOMP ${OpenMP_CXX_LIBRARIES})
endif()
add_dependencies(osmin ssl crypto)

include(android/AddQtAndroidApk.cmake)
add_qt_android_apk(osmin-apk osmin
NAME ${APP_NAME}
Expand All @@ -233,33 +218,38 @@ if(ANDROID)
PACKAGE_SOURCES ${PROJECT_SOURCE_DIR}/android/package-sources
BUILDTOOLS_REVISION ${QT_ANDROID_SDK_BUILDTOOLS_REVISION}
DEPENDS ssl crypto ${SHARED_LIBOMP}
PLUGINS ${PROJECT_SOURCE_DIR}/resources
ASSETS ${PROJECT_SOURCE_DIR}/resources
KEYSTORE ${KEYSTORE_FILE} ${KEYSTORE_ALIAS}
KEYSTORE_PASSWORD ${KEYSTORE_PASSWORD}
)
else()
if(BUILD_DEVICE_MOBILE)
add_definitions(-DDEVICE_MOBILE)
endif()
if(HAVE_DBUS)
add_definitions(-DHAVE_DBUS)
target_link_libraries(osmin PRIVATE Qt5::DBus)
endif()

set_target_properties(osmin PROPERTIES OUTPUT_NAME "${EXEC}")
install(TARGETS osmin RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
file(COPY "resources" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/resources
DESTINATION ${CMAKE_INSTALL_DATADIR}/${EXEC}
)
add_custom_target(
"run"
QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/backend/qml ${CMAKE_BINARY_DIR}/${EXEC} --debug
DEPENDS osmin
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY
)
add_custom_target(
"uninstall"
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
endif()

add_custom_target(
"run"
QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/backend/qml ${CMAKE_BINARY_DIR}/${EXEC} --debug
DEPENDS osmin
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY
)

add_custom_target(
"uninstall"
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
Loading

0 comments on commit 9f31a58

Please sign in to comment.