mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-12-03 02:15:41 +00:00
Conditionally build the Qt5 gui project.
Take the chance to introduce cmake_dependent_option. Using it for some of the old options as well.
This commit is contained in:
parent
705bf615ba
commit
17689af906
2 changed files with 178 additions and 12 deletions
|
@ -31,18 +31,34 @@ include(CPack)
|
|||
include(CTest)
|
||||
include(timestamp)
|
||||
include(shared_git_project)
|
||||
include(TargetArch)
|
||||
include(CMakeDependentOption)
|
||||
|
||||
option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF)
|
||||
option(DINDEXER_WITH_MEDIA_AUTODETECT "Enable code that tries to autodetect the media type and sets --type automatically" ON)
|
||||
option(DINDEXER_NATIVE_RELEASE "Pass the -march=native flag to the compiler for release builds" OFF)
|
||||
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION_MAJOR EQUAL "5")
|
||||
option(DINDEXER_CXX11_ABI "Controls if _GLIBCXX_USE_CXX11_ABI gets set to 0 or not" ON)
|
||||
target_architecture(DINDEXER_ARCH)
|
||||
if (DINDEXER_ARCH MATCHES "arm.*")
|
||||
set(is_arm ON)
|
||||
endif()
|
||||
cmake_dependent_option(DINDEXER_NATIVE_RELEASE "Pass the -march=native flag to the compiler for release builds" OFF "NOT is_arm" OFF)
|
||||
if(DINDEXER_NATIVE_RELEASE)
|
||||
set(march_flag "-march=native")
|
||||
else()
|
||||
set(march_flag "")
|
||||
endif()
|
||||
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION_MAJOR EQUAL "5")
|
||||
set(compiler_is_gnuxx_5plus ON)
|
||||
endif()
|
||||
|
||||
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem system)
|
||||
find_package(PostgreSQL 8.3 REQUIRED)
|
||||
find_package(YamlCpp 0.5.1 REQUIRED)
|
||||
import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}" "-O3 ${march_flag}")
|
||||
find_package(Qt5Qml 5.1 REQUIRED)
|
||||
|
||||
option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF)
|
||||
option(DINDEXER_WITH_MEDIA_AUTODETECT "Enable code that tries to autodetect the media type and sets --type automatically" ON)
|
||||
cmake_dependent_option(DINDEXER_WITH_DESKTOP_QT5_GUI "Enable the Qt5 GUI for desktop" ON "Qt5Qml_FOUND" OFF)
|
||||
cmake_dependent_option(DINDEXER_CXX11_ABI "Controls if _GLIBCXX_USE_CXX11_ABI gets set to 0 or not" ON "compiler_is_gnuxx_5plus" OFF)
|
||||
|
||||
set(DINDEXER_COPYRIGHT_YEARS "2015,2016")
|
||||
set(DINDEXER_ACTIONS_PATH "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE STRING "Actions search path")
|
||||
string(REGEX MATCH "[^/].*" ACTIONS_PATH_INSTALL "${DINDEXER_ACTIONS_PATH}")
|
||||
|
@ -67,11 +83,6 @@ if ("${DINDEXER_CONFIG_FILE}" STREQUAL "")
|
|||
endif()
|
||||
message(STATUS "Config file set to \"${DINDEXER_CONFIG_FILE}\"")
|
||||
|
||||
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem system)
|
||||
find_package(PostgreSQL 8.3 REQUIRED)
|
||||
find_package(YamlCpp 0.5.1 REQUIRED)
|
||||
import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}" "-O3 ${march_flag}")
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
add_library(${bare_name}-inc INTERFACE)
|
||||
|
||||
|
@ -118,7 +129,7 @@ target_include_directories(${bare_name}-inc
|
|||
INTERFACE ${CMAKE_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
if (NOT DINDEXER_CXX11_ABI AND CMAKE_CXX_COMPILER_VERSION_MAJOR EQUAL "5")
|
||||
if (NOT DINDEXER_CXX11_ABI)
|
||||
message(STATUS "CXX11 ABI disabled (_GLIBCXX_USE_CXX11_ABI=0)")
|
||||
add_definitions(
|
||||
#workaround for a bug in gcc 5.3 that is causing exceptions to slip
|
||||
|
@ -159,7 +170,10 @@ add_subdirectory(src/delete)
|
|||
add_subdirectory(src/locate)
|
||||
add_subdirectory(src/navigate)
|
||||
add_subdirectory(src/tag)
|
||||
add_subdirectory(src/gui)
|
||||
if (DINDEXER_WITH_DESKTOP_QT5_GUI)
|
||||
message(STATUS "Building Qt5 desktop GUI for ${bare_name}")
|
||||
add_subdirectory(src/gui)
|
||||
endif()
|
||||
|
||||
#Tests
|
||||
if (BUILD_TESTING)
|
||||
|
|
152
cmake/Modules/TargetArch.cmake
Normal file
152
cmake/Modules/TargetArch.cmake
Normal file
|
@ -0,0 +1,152 @@
|
|||
# Based on the Qt 5 processor detection code, so should be very accurate
|
||||
# http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/global/qprocessordetection.h?h=5.8
|
||||
# Currently handles arm (v5, v6, v7, v8), x86 (32/64), ia64, and ppc (32/64)
|
||||
|
||||
# Regarding POWER/PowerPC, just as is noted in the Qt source,
|
||||
# "There are many more known variants/revisions that we do not handle/detect."
|
||||
|
||||
set(archdetect_c_code "
|
||||
#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(__aarch64__)
|
||||
# if defined(__ARM_ARCH) && __ARM_ARCH > 1
|
||||
# define Q_PROCESSOR_ARM __ARM_ARCH
|
||||
# elif defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM > 1
|
||||
# define Q_PROCESSOR_ARM __TARGET_ARCH_ARM
|
||||
# endif
|
||||
# if defined(__ARM64_ARCH_8__) || defined(__aarch64__)
|
||||
# define Q_PROCESSOR_ARM 8
|
||||
# elif defined(__ARM_ARCH_7__) \\
|
||||
|| defined(__ARM_ARCH_7A__) \\
|
||||
|| defined(__ARM_ARCH_7R__) \\
|
||||
|| defined(__ARM_ARCH_7M__) \\
|
||||
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
|
||||
# define Q_PROCESSOR_ARM 7
|
||||
# elif defined(__ARM_ARCH_6__) \\
|
||||
|| defined(__ARM_ARCH_6J__) \\
|
||||
|| defined(__ARM_ARCH_6T2__) \\
|
||||
|| defined(__ARM_ARCH_6Z__) \\
|
||||
|| defined(__ARM_ARCH_6K__) \\
|
||||
|| defined(__ARM_ARCH_6ZK__) \\
|
||||
|| defined(__ARM_ARCH_6M__) \\
|
||||
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
|
||||
# define Q_PROCESSOR_ARM 6
|
||||
# elif defined(__ARM_ARCH_5TEJ__) \\
|
||||
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
|
||||
# define define Q_PROCESSOR_ARM 5
|
||||
# else
|
||||
# define Q_PROCESSOR_ARM 0
|
||||
# endif
|
||||
# if Q_PROCESSOR_ARM == 8
|
||||
# error cmake_ARCH armv8
|
||||
# elif Q_PROCESSOR_ARM == 7
|
||||
# error cmake_ARCH armv7
|
||||
# elif Q_PROCESSOR_ARM == 6
|
||||
# error cmake_ARCH armv6
|
||||
# elif Q_PROCESSOR_ARM == 5
|
||||
# error cmake_ARCH armv5
|
||||
# else
|
||||
# error cmake_ARCH arm
|
||||
# endif
|
||||
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
|
||||
# error cmake_ARCH i386
|
||||
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
|
||||
# error cmake_ARCH x86_64
|
||||
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
|
||||
# error cmake_ARCH ia64
|
||||
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|
||||
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|
||||
|| defined(_M_MPPC) || defined(_M_PPC)
|
||||
# if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
|
||||
# error cmake_ARCH ppc64
|
||||
# else
|
||||
# error cmake_ARCH ppc
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#error cmake_ARCH unknown
|
||||
")
|
||||
|
||||
# Set ppc_support to TRUE before including this file or ppc and ppc64
|
||||
# will be treated as invalid architectures since they are no longer supported by Apple
|
||||
|
||||
function(target_architecture output_var)
|
||||
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
|
||||
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
|
||||
# First let's normalize the order of the values
|
||||
|
||||
# Note that it's not possible to compile PowerPC applications if you are using
|
||||
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
|
||||
# disable it by default
|
||||
# See this page for more information:
|
||||
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
|
||||
|
||||
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
|
||||
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
|
||||
|
||||
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
|
||||
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
|
||||
set(osx_arch_ppc TRUE)
|
||||
elseif("${osx_arch}" STREQUAL "i386")
|
||||
set(osx_arch_i386 TRUE)
|
||||
elseif("${osx_arch}" STREQUAL "x86_64")
|
||||
set(osx_arch_x86_64 TRUE)
|
||||
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
|
||||
set(osx_arch_ppc64 TRUE)
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Now add all the architectures in our normalized order
|
||||
if(osx_arch_ppc)
|
||||
list(APPEND ARCH ppc)
|
||||
endif()
|
||||
|
||||
if(osx_arch_i386)
|
||||
list(APPEND ARCH i386)
|
||||
endif()
|
||||
|
||||
if(osx_arch_x86_64)
|
||||
list(APPEND ARCH x86_64)
|
||||
endif()
|
||||
|
||||
if(osx_arch_ppc64)
|
||||
list(APPEND ARCH ppc64)
|
||||
endif()
|
||||
else()
|
||||
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
|
||||
|
||||
enable_language(C)
|
||||
|
||||
# Detect the architecture in a rather creative way...
|
||||
# This compiles a small C program which is a series of ifdefs that selects a
|
||||
# particular #error preprocessor directive whose message string contains the
|
||||
# target architecture. The program will always fail to compile (both because
|
||||
# file is not a valid C program, and obviously because of the presence of the
|
||||
# #error preprocessor directives... but by exploiting the preprocessor in this
|
||||
# way, we can detect the correct target architecture even when cross-compiling,
|
||||
# since the program itself never needs to be run (only the compiler/preprocessor)
|
||||
try_run(
|
||||
run_result_unused
|
||||
compile_result_unused
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_BINARY_DIR}/arch.c"
|
||||
COMPILE_OUTPUT_VARIABLE ARCH
|
||||
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
|
||||
)
|
||||
|
||||
# Parse the architecture name from the compiler output
|
||||
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
|
||||
|
||||
# Get rid of the value marker leaving just the architecture name
|
||||
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
|
||||
|
||||
# If we are compiling with an unknown architecture this variable should
|
||||
# already be set to "unknown" but in the case that it's empty (i.e. due
|
||||
# to a typo in the code), then set it to unknown
|
||||
if (NOT ARCH)
|
||||
set(ARCH unknown)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(${output_var} "${ARCH}" PARENT_SCOPE)
|
||||
endfunction()
|
Loading…
Reference in a new issue