Warning, /education/kstars/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 PROJECT(kstars CXX C)
0002 set (KStars_VERSION_MAJOR 3)
0003 set (KStars_VERSION_MINOR 6)
0004 set (KStars_VERSION_REVISION 1)
0005 set (KSTARS_BUILD_RELEASE "Beta")
0006 set (CMAKE_CXX_STANDARD 17)
0007 
0008 set(QT_MIN_VERSION 5.12.8)
0009 set(KF5_MIN_VERSION 5.68.0)
0010 
0011 # Build KStars Lite with -DBUILD_KSTARS_LITE=ON
0012 option(BUILD_KSTARS_LITE "Build KStars Lite" OFF)
0013 
0014 # Build KStars documentation
0015 option(BUILD_DOC "Build Documentation" ON)
0016 
0017 # Fetch translations with -DFETCH_TRANSLATIONS=ON
0018 option(FETCH_TRANSLATIONS "Fetch Translations" OFF)
0019 
0020 # Build the Python bindings for the SkyMesh indexation
0021 option(BUILD_PYKSTARS "Build SkyMesh Python Bindings" OFF)
0022 
0023 # minimal requirements
0024 cmake_minimum_required (VERSION 3.16.0 FATAL_ERROR)
0025 
0026 # KStars Timestap build
0027 string(TIMESTAMP KSTARS_BUILD_TS UTC)
0028 
0029 # add EVERYTHING to the compile commands
0030 if(CMAKE_EXPORT_COMPILE_COMMANDS)
0031   set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
0032     ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
0033 endif()
0034 
0035 # For KStars Lite, we ALWAYS need to fetch translations
0036 if(BUILD_KSTARS_LITE)
0037     SET(FETCH_TRANSLATIONS ON)
0038 endif()
0039 
0040 # Set options for fetching translations
0041 if (FETCH_TRANSLATIONS)
0042 SET(KDE_L10N_AUTO_TRANSLATIONS ON)
0043 SET(KDE_L10N_BRANCH "trunk")
0044 endif()
0045 
0046 # Find includes in corresponding build directories
0047 set(CMAKE_INCLUDE_CURRENT_DIR ON)
0048 # Instruct CMake to run moc automatically when needed.
0049 set(CMAKE_AUTOMOC ON)
0050 
0051 # Ccache support
0052 IF (ANDROID OR UNIX OR APPLE)
0053     FIND_PROGRAM(CCACHE_FOUND ccache)
0054     SET(CCACHE_SUPPORT OFF CACHE BOOL "Enable ccache support")
0055     IF ((CCACHE_FOUND OR ANDROID) AND CCACHE_SUPPORT MATCHES ON)
0056         SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
0057         SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
0058     ENDIF ()
0059 ENDIF ()
0060 
0061 if(CMAKE_SYSTEM_NAME STREQUAL Android)
0062     add_definitions(-DANDROID -D__STDC_LIMIT_MACROS)
0063     set(ANDROID TRUE)
0064 endif()
0065 
0066 if("${CMAKE_TOOLCHAIN_FILE}" MATCHES "android.toolchain.cmake$")
0067     include(${CMAKE_BINARY_DIR}/kf5/kde/install/share/ECM/cmake/ECMConfig.cmake)
0068 endif()
0069 
0070 find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
0071 set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
0072 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})
0073 
0074 if(BUILD_KSTARS_LITE)
0075     if("${CMAKE_TOOLCHAIN_FILE}" MATCHES "android.toolchain.cmake$")
0076         set(QT_ANDROID $ENV{QT_ANDROID})
0077         set(Qt5Core_DIR "${QT_ANDROID}/lib/cmake/Qt5Core")
0078         set(Qt5Gui_DIR "${QT_ANDROID}/lib/cmake/Qt5Gui")
0079         set(Qt5Network_DIR "${QT_ANDROID}/lib/cmake/Qt5Network")
0080         set(Qt5Positioning_DIR "${QT_ANDROID}/lib/cmake/Qt5Positioning")
0081         set(Qt5Qml_DIR "${QT_ANDROID}/lib/cmake/Qt5Qml")
0082         set(Qt5Quick_DIR "${QT_ANDROID}/lib/cmake/Qt5Quick")
0083         set(Qt5Widgets_DIR "${QT_ANDROID}/lib/cmake/Qt5Widgets")
0084         include(${QT_ANDROID}/lib/cmake/Qt5/Qt5Config.cmake)
0085         include(${QT_ANDROID}/lib/cmake/Qt5Core/Qt5CoreConfig.cmake)
0086         include(${QT_ANDROID}/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake)
0087         include(${QT_ANDROID}/lib/cmake/Qt5Qml/Qt5QmlConfig.cmake)
0088         include(${QT_ANDROID}/lib/cmake/Qt5Quick/Qt5QuickConfig.cmake)
0089         include(${QT_ANDROID}/lib/cmake/Qt5QuickControls2/Qt5QuickControls2Config.cmake)
0090         include(${QT_ANDROID}/lib/cmake/Qt5Xml/Qt5XmlConfig.cmake)
0091         include(${QT_ANDROID}/lib/cmake/Qt5Svg/Qt5SvgConfig.cmake)
0092         include(${QT_ANDROID}/lib/cmake/Qt5Sql/Qt5SqlConfig.cmake)
0093         include(${QT_ANDROID}/lib/cmake/Qt5Network/Qt5NetworkConfig.cmake)
0094         include(${QT_ANDROID}/lib/cmake/Qt5Positioning/Qt5PositioningConfig.cmake)
0095         include(${QT_ANDROID}/lib/cmake/Qt5PositioningQuick/Qt5PositioningQuickConfig.cmake)
0096         include(${QT_ANDROID}/lib/cmake/Qt5Concurrent/Qt5ConcurrentConfig.cmake)
0097         include(${QT_ANDROID}/lib/cmake/Qt5AndroidExtras/Qt5AndroidExtrasConfig.cmake)
0098     else()
0099         if(ANDROID)
0100             list(APPEND QT_EXTRA_COMPONENTS AndroidExtras)
0101         else()
0102             list(APPEND QT_EXTRA_COMPONENTS PrintSupport)
0103         endif()
0104         find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Gui Qml Quick QuickControls2 Xml Svg Sql Network Positioning PositioningQuick Concurrent WebSockets ${QT_EXTRA_COMPONENTS})
0105     endif()
0106 else()
0107     #find_package(Qt5 5.4 REQUIRED COMPONENTS Gui Qml Quick Xml Sql Svg Network PrintSupport Positioning Concurrent)
0108     find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Gui Qml Quick Xml Sql Svg Network PrintSupport Concurrent WebSockets)
0109 endif()
0110 include(ExternalProject)
0111 include(ECMInstallIcons)
0112 include(ECMAddAppIcon)
0113 include(KDEInstallDirs)
0114 include(MacroBoolTo01)
0115 include(ECMQtDeclareLoggingCategory)
0116 include(KDECompilerSettings NO_POLICY_SCOPE)
0117 include(KDECMakeSettings)
0118 include(FeatureSummary)
0119 
0120 # Load the frameworks we need
0121 if(BUILD_KSTARS_LITE)
0122     if("${CMAKE_TOOLCHAIN_FILE}" MATCHES "android.toolchain.cmake$")
0123         set(KF5_VERSION 5.28.0)
0124         set(KF5_HOST_TOOLING /usr/lib/x86_64-linux-gnu/cmake/)
0125         include(${CMAKE_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5Config/KF5ConfigConfig.cmake)
0126         include(${CMAKE_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5I18n/KF5I18nConfig.cmake)
0127         include(${CMAKE_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5Plotting/KF5PlottingConfig.cmake)
0128     else()
0129         # Find Optional package NotifyConfig for desktop notifications
0130         find_package(KF5 ${KF5_MIN_VERSION} COMPONENTS NotifyConfig)
0131         MACRO_BOOL_TO_01(KF5NotifyConfig_FOUND HAVE_NOTIFYCONFIG)
0132 
0133         find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Auth Config Crash WidgetsAddons NewStuff I18n KIO XmlGui Plotting Notifications)
0134     endif()
0135 else(BUILD_KSTARS_LITE)
0136     # Find Optional package NotifyConfig for desktop notifications
0137     find_package(KF5 ${KF5_MIN_VERSION} COMPONENTS NotifyConfig)
0138     MACRO_BOOL_TO_01(KF5NotifyConfig_FOUND HAVE_NOTIFYCONFIG)
0139 
0140     find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
0141       Config
0142       Crash
0143       DocTools
0144       WidgetsAddons
0145       NewStuff
0146       I18n
0147       KIO
0148       XmlGui
0149       Plotting
0150       Notifications
0151     )
0152 endif(BUILD_KSTARS_LITE)
0153 
0154 ## Eigen3 Library
0155 find_package(Eigen3 REQUIRED CONFIG)
0156 
0157 ## CFITSIO Library
0158 if(ANDROID)
0159     if("${CMAKE_TOOLCHAIN_FILE}" MATCHES "android.toolchain.cmake$")
0160         set(extra_cmake "-DM_LIB=-lm")
0161     endif()
0162 
0163     find_program(DOS2UNIX dos2unix)
0164     if (NOT DOS2UNIX)
0165         message(FATAL_ERROR "Could not find dos2unix")
0166     endif()
0167 
0168     externalproject_add(cfitsio SOURCE_DIR "${CMAKE_BINARY_DIR}/packaging/android/3rdparty/cfitsio"
0169         URL https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio3370.tar.gz
0170         PATCH_COMMAND bash -c "cd ${CMAKE_BINARY_DIR}/packaging/android/3rdparty/cfitsio && ${DOS2UNIX} ${CMAKE_BINARY_DIR}/packaging/android/3rdparty/cfitsio/CMakeLists.txt && patch -p1 < ${CMAKE_SOURCE_DIR}/packaging/android/3rdparty/cfitsio.patch"
0171         CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${extra_cmake}
0172         BUILD_COMMAND make cfitsio
0173         BUILD_IN_SOURCE 1
0174         INSTALL_COMMAND "")
0175 
0176     set(CFITSIO_FOUND TRUE)
0177     set(CFITSIO_INCLUDE_DIR PUBLIC ${CMAKE_BINARY_DIR}/packaging/android/3rdparty/cfitsio)
0178     set(CFITSIO_LIBRARIES ${CMAKE_BINARY_DIR}/packaging/android/3rdparty/cfitsio/libcfitsio.a)
0179 else()
0180     if(BUILD_KSTARS_LITE)
0181         find_package(CFitsio REQUIRED)
0182     else()
0183         find_package(CFitsio)
0184     endif()
0185 endif()
0186 MACRO_BOOL_TO_01(CFITSIO_FOUND HAVE_CFITSIO)
0187 set_package_properties(CFitsio PROPERTIES DESCRIPTION "FITS IO Library" URL "https://heasarc.gsfc.nasa.gov/fitsio/fitsio.html" TYPE OPTIONAL PURPOSE "Support for the FITS (Flexible Image Transport System) data format in KStars.")
0188 
0189 ## INDI Library
0190 if (ANDROID)
0191     set(QT_ANDROID $ENV{QT_ANDROID})
0192     if("${CMAKE_TOOLCHAIN_FILE}" MATCHES "android.toolchain.cmake$")
0193         set(extra_cmake -DCMAKE_AR=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar)
0194     endif()
0195     externalproject_add(indi SOURCE_DIR "${CMAKE_BINARY_DIR}/packaging/android/indi"
0196         URL https://github.com/indilib/indi/archive/master.zip
0197         CONFIGURE_COMMAND cmake . -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \\
0198              -DINDI_BUILD_POSIX_CLIENT=OFF -DINDI_BUILD_SERVER=OFF -DINDI_BUILD_DRIVERS=OFF -DINDI_BUILD_UNITTESTS=OFF \\
0199              -DINDI_BUILD_DRIVERS=OFF -DINDI_BUILD_QT5_CLIENT=ON -DINDI_CALCULATE_MINMAX=ON \\
0200              -DCFITSIO_DIR=${CMAKE_BINARY_DIR}/packaging/android/3rdparty/cfitsio -DQT_ANDROID=${QT_ANDROID} -DCMAKE_PREFIX_PATH=${QT_ANDROID} ${extra_cmake}
0201         BUILD_COMMAND make
0202         BUILD_IN_SOURCE 1
0203         INSTALL_COMMAND "")
0204 
0205     set(INDI_FOUND TRUE)
0206     set(INDI_INCLUDE_DIR ${CMAKE_BINARY_DIR}/packaging/android/indi/libs/indibase ${CMAKE_BINARY_DIR}/packaging/android/indi ${CMAKE_BINARY_DIR}/packaging/android/indi/libs)
0207     set(INDI_CLIENT_ANDROID_LIBRARIES ${CMAKE_BINARY_DIR}/packaging/android/indi/libindiclientqt.a)
0208 else ()
0209     find_package(INDI 1.9.1)
0210 endif ()
0211 MACRO_BOOL_TO_01(INDI_FOUND HAVE_INDI)
0212 set_package_properties(INDI PROPERTIES DESCRIPTION "Astronomical instrumentation control" URL "https://www.indilib.org" TYPE OPTIONAL PURPOSE "Support for controlling astronomical devices on Linux with KStars.")
0213 
0214 if (INDI_FOUND AND NOT ANDROID)
0215     find_package(StellarSolver REQUIRED 2.2)
0216 endif(INDI_FOUND AND NOT ANDROID)
0217 MACRO_BOOL_TO_01(StellarSolver_FOUND HAVE_STELLARSOLVER)
0218 
0219 find_package(Nova)
0220 MACRO_BOOL_TO_01(NOVA_FOUND HAVE_LIBNOVA)
0221 if (NOVA_FOUND)
0222     include_directories(${NOVA_INCLUDE_DIR})
0223 endif()
0224 
0225 if(BUILD_TESTING)
0226     # Find liberfa, which we check our computation against
0227     find_package(ERFA)
0228     MACRO_BOOL_TO_01(ERFA_FOUND HAVE_LIBERFA)
0229     set_package_properties(ERFA PROPERTIES TYPE OPTIONAL PURPOSE "BSD-compatible version of SOFA, used to test core computations of KStars (only needed by tests)")
0230 endif ()
0231 
0232 ## Libraw
0233 if(BUILD_KSTARS_LITE AND ANDROID)
0234     # OpenMP needed for LibRaw
0235     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp -DLIBRAW_USE_OPENMP")
0236     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -DLIBRAW_USE_OPENMP")
0237     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgomp")
0238 
0239     externalproject_add(raw SOURCE_DIR "${CMAKE_BINARY_DIR}/packaging/android/3rdparty/libraw"
0240         URL https://www.libraw.org/data/LibRaw-0.17.2.tar.gz
0241         PATCH_COMMAND bash -c "cd ${CMAKE_BINARY_DIR}/packaging/android/3rdparty/libraw && wget -qO- https://github.com/LibRaw/LibRaw-cmake/archive/master.zip | jar xvf /dev/stdin && rm -rf cmake && mv -f LibRaw-cmake-master/CMakeLists.txt LibRaw-cmake-master/cmake . && patch -p1 < ${CMAKE_SOURCE_DIR}/packaging/android/3rdparty/libraw.patch"
0242         CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DENABLE_OPENMP=OFF -DENABLE_LCMS=OFF
0243         BUILD_COMMAND make raw
0244         BUILD_IN_SOURCE 1
0245         INSTALL_COMMAND "")
0246     include_directories(${CMAKE_BINARY_DIR}/packaging/android/3rdparty/libraw)
0247     set(LIBRAW_LIBRARIES ${CMAKE_BINARY_DIR}/packaging/android/3rdparty/libraw/libraw.a)
0248     set(LibRaw_FOUND true)
0249 else()
0250     find_package(LibRaw)
0251 endif()
0252 MACRO_BOOL_TO_01(LibRaw_FOUND HAVE_LIBRAW)
0253 set_package_properties(LibRaw PROPERTIES DESCRIPTION "Library for reading RAW files" URL "https://www.libraw.org/" TYPE OPTIONAL PURPOSE "Support for reading and displaying RAW files in KStars.")
0254 
0255 ## WCS Library
0256 find_package(WCSLIB)
0257 MACRO_BOOL_TO_01(WCSLIB_FOUND HAVE_WCSLIB)
0258 set_package_properties(WCSLIB PROPERTIES DESCRIPTION "World Coordinate System library" URL "https://www.atnf.csiro.au/people/mcalabre/WCS" TYPE OPTIONAL PURPOSE "WCS enables KStars to read and process world coordinate systems in FITS header.")
0259 
0260 ## XPlanet
0261 find_package(Xplanet)
0262 set_package_properties(Xplanet PROPERTIES DESCRIPTION "Renders an image of all the major planets and most satellites" URL "http://xplanet.sourceforge.net" TYPE RUNTIME PURPOSE "Gives KStars support for xplanet.")
0263 
0264 # Qt5 Data Visualization
0265 find_package(Qt5DataVisualization)
0266 MACRO_BOOL_TO_01(Qt5DataVisualization_FOUND HAVE_DATAVISUALIZATION)
0267 
0268 ## Astrometry.net
0269 #find_package(AstrometryNet)
0270 #set_package_properties(AstrometryNet PROPERTIES DESCRIPTION "Astrometrics Library" URL "http://www.astrometry.net" TYPE RUNTIME PURPOSE "Support for plate solving in KStars.")
0271 
0272 ## Key Chain
0273 find_package(Qt5Keychain)
0274 MACRO_BOOL_TO_01(Qt5Keychain_FOUND HAVE_KEYCHAIN)
0275 
0276 ## OpenGL
0277 find_package(OpenGL)
0278 set_package_properties(OpenGL PROPERTIES DESCRIPTION "Open Graphics Library" URL "https://www.opengl.org/" TYPE OPTIONAL PURPOSE "Support for hardware rendering in KStars.")
0279 
0280 add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
0281 add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
0282 if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT WIN32)
0283   add_definitions(-DQT_STRICT_ITERATORS)
0284 endif()
0285 add_definitions(-DQT_NO_CAST_TO_ASCII)
0286 
0287 # Needed for htmesh, and libraw
0288 kde_enable_exceptions()
0289 
0290 if (UNIX)
0291 
0292   # TEMPORARY: To disable QCustomPlot warning until 2.0.0 is released which fixes these warnings
0293   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-non-virtual-dtor")
0294 
0295   # Optimize binary size by dropping unneeded symbols at linking stage
0296   if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
0297     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections")
0298     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
0299   endif()
0300 endif(UNIX)
0301 
0302 # Optimize binary size by dropping unneeded symbols at linking stage
0303 if (ANDROID)
0304     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden")
0305     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
0306 endif ()
0307 
0308 # Add security (hardening flags)
0309 IF (UNIX OR APPLE OR ANDROID)
0310     SET(SEC_COMP_FLAGS "-D_FORTIFY_SOURCE=2 -fstack-protector-all -Wcast-align -fPIE")
0311     IF (NOT ANDROID AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE)
0312         SET(SEC_COMP_FLAGS "${SEC_COMP_FLAGS} -Wa,--noexecstack")
0313     ENDIF ()
0314     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SEC_COMP_FLAGS}")
0315     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SEC_COMP_FLAGS}")
0316     SET(SEC_LINK_FLAGS "")
0317 
0318     include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/CheckNodump.cmake")
0319     check_nodump(NODUMP_FLAGS)
0320 
0321     IF (NOT APPLE)
0322         SET(SEC_LINK_FLAGS "${SEC_LINK_FLAGS} ${NODUMP_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
0323     ENDIF ()
0324     IF (NOT ANDROID AND NOT APPLE)
0325         SET(SEC_LINK_FLAGS "${SEC_LINK_FLAGS} -pie")
0326     ENDIF ()
0327     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SEC_LINK_FLAGS}")
0328     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SEC_LINK_FLAGS}")
0329 ENDIF ()
0330 
0331 # Clang Format support
0332 IF (UNIX OR APPLE)
0333     SET(FORMAT_CODE OFF CACHE BOOL "Enable Clang Format")
0334     IF (FORMAT_CODE MATCHES ON)
0335         FILE(GLOB_RECURSE ALL_SOURCE_FILES *.c *.cpp *.h)
0336 
0337         FOREACH(SOURCE_FILE ${ALL_SOURCE_FILES})
0338             STRING(FIND ${SOURCE_FILE} ${CMAKE_SOURCE_DIR} DIR_FOUND)
0339             IF (NOT ${DIR_FOUND} EQUAL 0)
0340                 LIST(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
0341             ENDIF ()
0342         ENDFOREACH ()
0343 
0344         FIND_PROGRAM(CLANGFORMAT_EXE NAMES clang-format-5.0)
0345         IF (CLANGFORMAT_EXE)
0346             ADD_CUSTOM_TARGET(clang-format COMMAND ${CLANGFORMAT_EXE} -style=file -i ${ALL_SOURCE_FILES})
0347         ENDIF ()
0348     ENDIF ()
0349 ENDIF ()
0350 
0351 SET(FIX_WARNINGS OFF CACHE BOOL "Enable strict compilation mode to turn compiler warnings to errors")
0352 # Warning, debug and linker flags
0353 IF (UNIX OR APPLE)
0354     SET(COMP_FLAGS "")
0355     SET(LINKER_FLAGS "")
0356     # Verbose warnings and turns all to errors
0357     SET(COMP_FLAGS "${COMP_FLAGS} -Wall -Wextra")
0358     IF (FIX_WARNINGS)
0359         SET(COMP_FLAGS "${COMP_FLAGS} -Werror")
0360     ENDIF ()
0361     # Omit problematic warnings
0362     IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
0363         SET(COMP_FLAGS "${COMP_FLAGS} -Wno-unused-but-set-variable")
0364         SET(COMP_FLAGS "${COMP_FLAGS} -Wno-stringop-truncation")
0365     ENDIF ()
0366     IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.9.9)
0367         SET(COMP_FLAGS "${COMP_FLAGS} -Wno-format-truncation")
0368     ENDIF ()
0369     IF (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
0370         SET(COMP_FLAGS "${COMP_FLAGS} -Wno-nonnull -Wno-deprecated-declarations")
0371     ENDIF ()
0372     IF (BUILD_KSTARS_LITE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
0373         SET(COMP_FLAGS "${COMP_FLAGS} -Wno-overloaded-virtual")
0374     ENDIF ()
0375 
0376     SET(COMP_FLAGS "${COMP_FLAGS} -g")
0377 
0378     # Note: The following flags are problematic on older systems with gcc 4.8
0379     IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9.9))
0380         IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
0381             SET(COMP_FLAGS "${COMP_FLAGS} -Wno-unused-command-line-argument")
0382         ENDIF ()
0383         FIND_PROGRAM(LDGOLD_FOUND ld.gold)
0384         SET(LDGOLD_SUPPORT OFF CACHE BOOL "Enable ld.gold support")
0385         # Optional ld.gold is 2x faster than normal ld
0386         IF (LDGOLD_FOUND AND LDGOLD_SUPPORT MATCHES ON AND NOT APPLE AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES arm)
0387             SET(LINKER_FLAGS "${LINKER_FLAGS} -fuse-ld=gold")
0388             # We have Gsl library what is a special case for linking:
0389             # The gsl library must be linked with cblas. There are two alternatives for this: libcblas or libgslcblas.
0390             # For example, CMake gets the GSL_LIBRARIES linking flags from the pkgconfig (gsl.pc) file on Ubuntu.
0391             # This file defines -lgsl -lglscblas for linking flags and if KStars is compiled with Clang, the linker
0392             # finds out magically that KStars must be linked against glscblas library, but gslcblas is omitted in linking
0393             # stage if KStars is built with gcc. The linker must be instructed explicitly to link against all libraries
0394             # passed on command line by -Wl,--no-as-needed.
0395             SET(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--no-as-needed")
0396             # Use Identical Code Folding
0397             SET(COMP_FLAGS "${COMP_FLAGS} -ffunction-sections")
0398             SET(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--icf=safe")
0399             # Compress the debug sections
0400             # Note: Before valgrind 3.12.0, patch should be applied for valgrind (https://bugs.kde.org/show_bug.cgi?id=303877)
0401             IF (NOT APPLE AND NOT ANDROID AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES arm AND NOT CMAKE_CXX_CLANG_TIDY)
0402                 SET(COMP_FLAGS "${COMP_FLAGS} -Wa,--compress-debug-sections")
0403                 SET(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--compress-debug-sections=zlib")
0404             ENDIF ()
0405         ENDIF ()
0406     ENDIF ()
0407 
0408     # Apply the flags
0409     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMP_FLAGS}")
0410     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMP_FLAGS}")
0411     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
0412     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
0413 ENDIF ()
0414 
0415 # Sanitizer support
0416 SET(SANITIZERS OFF CACHE BOOL "Sanitizer support for gcc and Clang")
0417 IF (SANITIZERS AND
0418     ((UNIX AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR CMAKE_COMPILER_IS_GNUCXX) OR
0419      (APPLE AND (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_COMPILER_IS_GNUCXX))))
0420     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer")
0421     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer")
0422     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer")
0423     SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer")
0424 ENDIF ()
0425 
0426 # Unity build support
0427 SET(UNITY_BUILD OFF CACHE BOOL "Enable Unity Build")
0428 INCLUDE(UnityBuild)
0429 
0430 configure_file(
0431     ${CMAKE_CURRENT_SOURCE_DIR}/config-kstars.h.cmake
0432     ${CMAKE_CURRENT_BINARY_DIR}/config-kstars.h
0433 )
0434 
0435 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/kstars/version.h.cmake
0436                ${CMAKE_CURRENT_BINARY_DIR}/kstars/version.h )
0437 
0438 # let our config.h be found first in any case
0439 include_directories (BEFORE ${CMAKE_CURRENT_BINARY_DIR})
0440 
0441 if (BUILD_DOC)
0442     add_subdirectory(doc)
0443 endif()
0444 
0445 # add some utility headers
0446 include_directories(utils)
0447 
0448 add_subdirectory(kstars)
0449 add_subdirectory(datahandlers)
0450 
0451 IF (NOT ANDROID)
0452     IF (BUILD_TESTING)
0453     enable_testing(true)
0454     add_subdirectory(Tests)
0455     ENDIF()
0456     # Make it possible to use the po files fetched by the fetch-translations step
0457     if (FETCH_TRANSLATIONS)
0458         ki18n_install("${CMAKE_CURRENT_BINARY_DIR}/po")
0459     else()
0460         ki18n_install(po)
0461         find_package(KF5DocTools CONFIG)
0462         if(KF5DocTools_FOUND)
0463             kdoctools_install(po)
0464         endif()
0465     endif()
0466 ENDIF ()
0467 
0468 if(NOT APPLE) #This is not used on MacOS
0469     install(FILES org.kde.kstars.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})
0470 endif(NOT APPLE)
0471 
0472 feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
0473 
0474 # Only build k5auth for Linux
0475 # JM 2018-09-26: KAuth is disabled due to reliability issues.
0476 #if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
0477 #    # This helper file is generated to download astrometry.net index files.
0478 #    add_executable(kauth_kstars_helper kstars/auxiliary/downloadhelper.cpp  ${helper_mocs})
0479 #    target_link_libraries(kauth_kstars_helper Qt5::Core)
0480 #    target_link_libraries(kauth_kstars_helper Qt5::Widgets)
0481 #    target_link_libraries(kauth_kstars_helper KF5::Auth)
0482 #    install(TARGETS kauth_kstars_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
0483 #    kauth_install_helper_files(kauth_kstars_helper org.kde.kf5auth.kstars root)
0484 #    kauth_install_actions(org.kde.kf5auth.kstars org.kde.kf5auth.kstars.actions)
0485 #ENDIF ()
0486 
0487 # Final package generation
0488 if ("${CMAKE_TOOLCHAIN_FILE}" MATCHES "android.toolchain.cmake$")
0489     set(EXPORT_DIR "${CMAKE_BINARY_DIR}/packaging/android/kstars_build_apk/")
0490     set(ANDROID_APK_DIR "${CMAKE_SOURCE_DIR}/packaging/android/apk/")
0491     set(EXECUTABLE_DESTINATION_PATH "${EXPORT_DIR}/libs/armeabi-v7a/libkstars.so")
0492     set(ANDROID_NDK $ENV{CMAKE_ANDROID_NDK})
0493     set(ANDROID_SDK_ROOT $ENV{ANDROID_SDK_ROOT})
0494     set(ANDROID_API_LEVEL $ENV{ANDROID_API_LEVEL})
0495     set(ANDROID_TOOLCHAIN arm-linux-androideabi)
0496     set(ANDROID_GCC_VERSION 4.9)
0497     set(ANDROID_ABI armeabi-v7a)
0498     set(_HOST "${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
0499     string(TOLOWER "${_HOST}" _HOST)
0500     set(ANDROID_SDK_BUILD_TOOLS_REVISION 21.1.1)
0501     set(ANDROID_KEYSTORE $ENV{ANDROID_KEYSTORE})
0502     set(ANDROID_KEYSTORE_ALIAS $ENV{ANDROID_KEYSTORE_ALIAS})
0503     configure_file("${CMAKE_SOURCE_DIR}/packaging/android/deployment-file.json.in" "${CMAKE_BINARY_DIR}/packaging/android/kstars-deployment.json.in")
0504 
0505 
0506     add_custom_target(create-apk-debug-kstars
0507         COMMAND cmake -E echo "Generating $<TARGET_NAME:kstars> with $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt"
0508         COMMAND cmake -E remove_directory "${EXPORT_DIR}"
0509         COMMAND cmake -E copy_directory "${CMAKE_SOURCE_DIR}/packaging/android/apk" "${EXPORT_DIR}"
0510         COMMAND cmake -E copy "$<TARGET_FILE:kstars>" "${EXECUTABLE_DESTINATION_PATH}"
0511         COMMAND cmake -DINPUT_FILE="${CMAKE_BINARY_DIR}/packaging/android/kstars-deployment.json.in" -DOUTPUT_FILE="${CMAKE_BINARY_DIR}/packaging/android/kstars-deployment.json" "-DTARGET_DIR=${CMAKE_BINARY_DIR}/kstars" "-DTARGET_NAME=kstars" "-DEXPORT_DIR=${CMAKE_INSTALL_PREFIX}" -P ${CMAKE_SOURCE_DIR}/packaging/android/specifydependencies.cmake
0512         COMMAND $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt --input "${CMAKE_BINARY_DIR}/packaging/android/kstars-deployment.json" --output "${EXPORT_DIR}" --android-platform android-${ANDROID_API_LEVEL} --debug --deployment bundled "\\$(ARGS)"
0513         )
0514     add_custom_target(create-apk-release-kstars
0515         COMMAND cmake -E echo "Generating $<TARGET_NAME:kstars> with $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt"
0516         COMMAND cmake -E remove_directory "${EXPORT_DIR}"
0517         COMMAND cmake -E copy_directory "${CMAKE_SOURCE_DIR}/packaging/android/apk" "${EXPORT_DIR}"
0518         COMMAND cmake -E copy "$<TARGET_FILE:kstars>" "${EXECUTABLE_DESTINATION_PATH}"
0519         COMMAND cmake -DINPUT_FILE="${CMAKE_BINARY_DIR}/packaging/android/kstars-deployment.json.in" -DOUTPUT_FILE="${CMAKE_BINARY_DIR}/packaging/android/kstars-deployment.json" "-DTARGET_DIR=${CMAKE_BINARY_DIR}/kstars" "-DTARGET_NAME=kstars" "-DEXPORT_DIR=${CMAKE_INSTALL_PREFIX}" -P ${CMAKE_SOURCE_DIR}/packaging/android/specifydependencies.cmake
0520         COMMAND $<TARGET_FILE_DIR:Qt5::qmake>/androiddeployqt --input "${CMAKE_BINARY_DIR}/packaging/android/kstars-deployment.json" --output "${EXPORT_DIR}" --android-platform android-${ANDROID_API_LEVEL} --release --deployment bundled "\\$(ARGS)"
0521         )
0522     add_custom_target(install-apk-debug-kstars
0523         COMMAND adb install -r ${CMAKE_BINARY_DIR}/packaging/android/kstars_build_apk//bin/QtApp-debug.apk
0524         )
0525 
0526     if (ANDROID_KEYSTORE AND ANDROID_KEYSTORE_ALIAS)
0527         add_custom_target(sign-apk-kstars
0528             COMMAND jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ${ANDROID_KEYSTORE} ${CMAKE_BINARY_DIR}/packaging/android/kstars_build_apk/bin/QtApp-release-unsigned.apk ${ANDROID_KEYSTORE_ALIAS}
0529             COMMAND rm -rf ${CMAKE_BINARY_DIR}/packaging/android/kstars_build_apk/bin/kstars-signed.apk
0530             COMMAND zipalign -v 4 ${CMAKE_BINARY_DIR}/packaging/android/kstars_build_apk/bin/QtApp-release-unsigned.apk ${CMAKE_BINARY_DIR}/packaging/android/kstars_build_apk/bin/kstars-signed.apk
0531             )
0532     endif ()
0533 endif ()