Commit 9edcaeea authored by Valentin Platzgummer's avatar Valentin Platzgummer

merged with upstream 1

parents c3c2876d 28d2157f
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
path = libs/mavlink/include/mavlink/v2.0 path = libs/mavlink/include/mavlink/v2.0
url = https://github.com/mavlink/c_library_v2.git url = https://github.com/mavlink/c_library_v2.git
<<<<<<< HEAD <<<<<<< HEAD
[submodule "libs/WGS84toCartesian"]
path = libs/WGS84toCartesian
url = https://github.com/chrberger/WGS84toCartesian.git
[submodule "libs/polylabel"] [submodule "libs/polylabel"]
path = libs/polylabel path = libs/polylabel
url = https://github.com/mapbox/polylabel.git url = https://github.com/mapbox/polylabel.git
...@@ -27,10 +24,10 @@ ...@@ -27,10 +24,10 @@
path = libs/or-tools path = libs/or-tools
url = https://github.com/google/or-tools.git url = https://github.com/google/or-tools.git
======= =======
>>>>>>> upstream_merge
[submodule "libs/OpenSSL/android_openssl"] [submodule "libs/OpenSSL/android_openssl"]
path = libs/OpenSSL/android_openssl path = libs/OpenSSL/android_openssl
url = https://github.com/Auterion/android_openssl url = https://github.com/Auterion/android_openssl
[submodule "libs/qmlglsink/gst-plugins-good"] [submodule "libs/qmlglsink/gst-plugins-good"]
path = libs/qmlglsink/gst-plugins-good path = libs/qmlglsink/gst-plugins-good
url = https://github.com/mavlink/gst-plugins-good.git url = https://github.com/mavlink/gst-plugins-good.git
>>>>>>> upstream_merge
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.10)
project(QGroundControl LANGUAGES CXX) project(QGroundControl LANGUAGES C CXX)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage") set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(FeatureSummary)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-Wall -Wextra)
endif()
# CMake build type # CMake build type
# Debug Release RelWithDebInfo MinSizeRel Coverage # Debug Release RelWithDebInfo MinSizeRel Coverage
if (NOT CMAKE_BUILD_TYPE) if (NOT CMAKE_BUILD_TYPE)
...@@ -11,37 +23,11 @@ if (NOT CMAKE_BUILD_TYPE) ...@@ -11,37 +23,11 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type" FORCE) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type" FORCE)
endif() endif()
if(DEFINED ENV{QT_VERSION})
set(QT_VERSION $ENV{QT_VERSION})
endif()
if(NOT QT_VERSION)
# try Qt 5.9.5 if none specified
set(QT_VERSION "5.9.5")
endif()
if(DEFINED ENV{QT_MKSPEC})
set(QT_MKSPEC $ENV{QT_MKSPEC})
endif()
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
if(NOT QT_MKSPEC)
if(APPLE)
set(QT_MKSPEC clang_64)
elseif(LINUX)
set(QT_MKSPEC gcc_64)
elseif(WIN32)
set(QT_MKSPEC msvc2017_64)
#set(QT_MKSPEC winrt_x64_msvc2017)
endif()
endif()
# Add folder where are supportive functions # Add folder where are supportive functions
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# Configure Qt5 to get necessary variables
include(Qt5QGCConfiguration)
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Qt version: ${QT_VERSION}") message(STATUS "Qt version: ${QT_VERSION}")
message(STATUS "Qt spec: ${QT_MKSPEC}") message(STATUS "Qt spec: ${QT_MKSPEC}")
...@@ -50,31 +36,14 @@ set(COMPANY "Mavlink") ...@@ -50,31 +36,14 @@ set(COMPANY "Mavlink")
set(COPYRIGHT "Copyright (c) 2018 QGroundControl. All rights reserved.") set(COPYRIGHT "Copyright (c) 2018 QGroundControl. All rights reserved.")
set(IDENTIFIER "io.mavlink.qgroundcontrol") set(IDENTIFIER "io.mavlink.qgroundcontrol")
execute_process(
COMMAND git submodule update --init
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND git describe --always --tags
OUTPUT_VARIABLE git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_definitions( add_definitions(
-DQGC_APPLICATION_NAME="QGCWima" -DQGC_APPLICATION_NAME="QGroundControl"
-DQGC_ORG_NAME="QGCWima.org" -DQGC_ORG_NAME="QGroundControl.org"
-DQGC_ORG_DOMAIN="org.qgroundcontrol" -DQGC_ORG_DOMAIN="org.qgroundcontrol"
) )
message(STATUS "QGroundControl version: ${git_tag}") include(Git)
message(STATUS "QGroundControl version: ${GIT_VERSION}")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#============================================================================= #=============================================================================
# ccache # ccache
...@@ -85,12 +54,67 @@ if (CCACHE AND CCACHE_PROGRAM AND NOT DEFINED ENV{CCACHE_DISABLE}) ...@@ -85,12 +54,67 @@ if (CCACHE AND CCACHE_PROGRAM AND NOT DEFINED ENV{CCACHE_DISABLE})
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif() endif()
#=============================================================================
# Compile QML
#
option(COMPILE_QML "Pre-compile QML files using the Qt Quick compiler." FALSE)
add_feature_info(COMPILE_QML COMPILE_QML "Pre-compile QML files using the Qt Quick compiler.")
if(COMPILE_QML)
find_package(Qt5QuickCompiler)
set_package_properties(Qt5QuickCompiler PROPERTIES
DESCRIPTION "Pre-compile QML files using the Qt Quick compiler."
TYPE OPTIONAL
)
endif()
#=============================================================================
# Debug QML
#
option(DEBUG_QML "Build QGroundControl with QML debugging/profiling support." FALSE)
add_feature_info(DEBUG_QML DEBUG_QML "Build QGroundControl with QML debugging/profiling support.")
if(DEBUG_QML)
message(STATUS "To enable the QML debugger/profiler, run with: '-qmljsdebugger=port:1234'")
add_definitions(-DQMLJSDEBUGGER)
add_definitions(-DQT_DECLARATIVE_DEBUG)
add_definitions(-DQT_QML_DEBUG)
endif()
#=============================================================================
# GStreamer
#
find_package(PkgConfig)
pkg_check_modules(GST
gstreamer-1.0>=1.14
gstreamer-video-1.0>=1.14
gstreamer-gl-1.0>=1.14
egl
)
if (GST_FOUND)
include_directories(
${GST_INCLUDE_DIRS}
src/Taisync
src/Microhard
)
add_definitions(
-DQGC_GST_STREAMING
-DQGC_GST_TAISYNC_ENABLED
-DQGC_GST_MICROHARD_ENABLED
)
endif()
add_definitions(
-DQGC_ENABLE_MAVLINK_INSPECTOR
)
#============================================================================= #=============================================================================
# Qt5 # Qt5
# #
find_package(Qt5 ${QT_VERSION} find_package(Qt5 ${QT_VERSION}
COMPONENTS COMPONENTS
Bluetooth Bluetooth
Charts
Concurrent Concurrent
Core Core
Location Location
...@@ -98,7 +122,9 @@ find_package(Qt5 ${QT_VERSION} ...@@ -98,7 +122,9 @@ find_package(Qt5 ${QT_VERSION}
Network Network
Positioning Positioning
Quick Quick
QuickControls2
QuickWidgets QuickWidgets
OpenGL
Sql Sql
Svg Svg
Test Test
...@@ -107,9 +133,7 @@ find_package(Qt5 ${QT_VERSION} ...@@ -107,9 +133,7 @@ find_package(Qt5 ${QT_VERSION}
Xml Xml
REQUIRED REQUIRED
HINTS HINTS
$ENV{HOME}/Qt/${QT_VERSION}/${QT_MKSPEC} ${QT_LIBRARY_HINTS}
$ENV{QT_PATH}/${QT_VERSION}/${QT_MKSPEC}
C:/Qt
) )
if(NOT QT_MKSPEC MATCHES "winrt") if(NOT QT_MKSPEC MATCHES "winrt")
...@@ -118,50 +142,12 @@ if(NOT QT_MKSPEC MATCHES "winrt") ...@@ -118,50 +142,12 @@ if(NOT QT_MKSPEC MATCHES "winrt")
SerialPort SerialPort
REQUIRED REQUIRED
HINTS HINTS
$ENV{HOME}/Qt/${QT_VERSION}/${QT_MKSPEC} ${QT_LIBRARY_HINTS}
$ENV{QT_PATH}/${QT_VERSION}/${QT_MKSPEC}
C:/Qt
)
endif()
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
include(CTest)
enable_testing()
add_definitions(-DUNITTEST_BUILD)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# clang and AppleClang
add_compile_options(
-Wall
-Wextra
-Wno-address-of-packed-member # ignore for mavlink
)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GCC
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
add_compile_options(-fdiagnostics-color=always)
endif()
add_compile_options(
-Wall
-Wextra
) )
elseif (WIN32)
add_definitions(-D_USE_MATH_DEFINES)
add_compile_options(
/wd4244 # warning C4244: '=': conversion from 'double' to 'float', possible loss of data
)
endif() endif()
# TODO: get qtquick compiler working # Sets the default flags for compilation and linking.
#qtquick_compiler_add_resources(QGC_RESOURCES ${QGC_RESOURCES} include(CompileOptions)
#find_package(Qt5QuickCompiler)
include_directories( include_directories(
libs/eigen libs/eigen
...@@ -177,11 +163,9 @@ add_subdirectory(libs) ...@@ -177,11 +163,9 @@ add_subdirectory(libs)
add_subdirectory(src) add_subdirectory(src)
set(QGC_RESOURCES set(QGC_RESOURCES
#HackAndroidFileDialog.qrc
HackFileDialog.qrc
qgcresources.qrc qgcresources.qrc
qgroundcontrol.qrc qgroundcontrol.qrc
qgcimages.qrc
src/FirmwarePlugin/APM/APMResources.qrc src/FirmwarePlugin/APM/APMResources.qrc
src/FirmwarePlugin/PX4/PX4Resources.qrc src/FirmwarePlugin/PX4/PX4Resources.qrc
src/Airmap/airmap.qrc src/Airmap/airmap.qrc
...@@ -213,56 +197,5 @@ if(NOT QT_MKSPEC MATCHES "winrt") ...@@ -213,56 +197,5 @@ if(NOT QT_MKSPEC MATCHES "winrt")
) )
endif() endif()
if(LINUX) include(QGCDeploy)
elseif(APPLE)
get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${_qt_bin_dir}")
add_custom_command(TARGET QGroundControl
POST_BUILD
COMMAND
${MACDEPLOYQT_EXECUTABLE} $<TARGET_FILE_DIR:QGroundControl>/../.. -appstore-compliant -qmldir=${CMAKE_SOURCE_DIR}/src
COMMAND
rsync -a ${CMAKE_SOURCE_DIR}/libs/lib/Frameworks $<TARGET_FILE_DIR:QGroundControl>/../../Contents/
COMMAND
${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/SDL2.framework/Versions/A/SDL2" "@executable_path/../Frameworks/SDL2.framework/Versions/A/SDL2" $<TARGET_FILE:QGroundControl>
)
set_target_properties(QGroundControl PROPERTIES MACOSX_BUNDLE YES)
elseif(WIN32)
if(MSVC) # Check if we are using the Visual Studio compiler
set_target_properties(${PROJECT_NAME} PROPERTIES
WIN32_EXECUTABLE YES
LINK_FLAGS "/ENTRY:mainCRTStartup"
)
endif()
# deploy
include(Windeployqt)
windeployqt(QGroundControl "QGroundControl-installer.exe")
elseif(ANDROID)
include(AddQtAndroidApk)
add_qt_android_apk(QGroundControl.apk QGroundControl
PACKAGE_NAME "io.mavlink.qgroundcontrol"
#KEYSTORE ${CMAKE_CURRENT_LIST_DIR}/mykey.keystore myalias
#KEYSTORE_PASSWORD xxxxx
)
elseif(LINUX)
# TODO: investigate https://github.com/probonopd/linuxdeployqt
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/release/package/QGroundControl.AppImage
COMMAND ${CMAKE_SOURCE_DIR}/deploy/create_linux_appimage.sh ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/release/package;
DEPENDS QGroundControl
USES_TERMINAL
)
add_custom_target(appimage DEPENDS ${CMAKE_BINARY_DIR}/release/package/QGroundControl.AppImage)
endif()
<RCC> <RCC>
<qresource prefix="/unittest"> <qresource prefix="/unittest">
<file alias="SectionTest.plan">src/MissionManager/UnitTest/SectionTest.plan</file> <file alias="SectionTest.plan">src/MissionManager/UnitTest/SectionTest.plan</file>
<file alias="MavCmdInfoCommon.json">src/MissionManager/UnitTest/MavCmdInfoCommon.json</file> <file alias="UT-MavCmdInfoCommon.json">src/MissionManager/UnitTest/UT-MavCmdInfoCommon.json</file>
<file alias="MavCmdInfoFixedWing.json">src/MissionManager/UnitTest/MavCmdInfoFixedWing.json</file> <file alias="UT-MavCmdInfoFixedWing.json">src/MissionManager/UnitTest/UT-MavCmdInfoFixedWing.json</file>
<file alias="MavCmdInfoMultiRotor.json">src/MissionManager/UnitTest/MavCmdInfoMultiRotor.json</file> <file alias="UT-MavCmdInfoMultiRotor.json">src/MissionManager/UnitTest/UT-MavCmdInfoMultiRotor.json</file>
<file alias="MavCmdInfoRover.json">src/MissionManager/UnitTest/MavCmdInfoRover.json</file> <file alias="UT-MavCmdInfoRover.json">src/MissionManager/UnitTest/UT-MavCmdInfoRover.json</file>
<file alias="MavCmdInfoSub.json">src/MissionManager/UnitTest/MavCmdInfoSub.json</file> <file alias="UT-MavCmdInfoSub.json">src/MissionManager/UnitTest/UT-MavCmdInfoSub.json</file>
<file alias="MavCmdInfoVTOL.json">src/MissionManager/UnitTest/MavCmdInfoVTOL.json</file> <file alias="UT-MavCmdInfoVTOL.json">src/MissionManager/UnitTest/UT-MavCmdInfoVTOL.json</file>
<file alias="MissionPlanner.waypoints">src/MissionManager/UnitTest/MissionPlanner.waypoints</file> <file alias="MissionPlanner.waypoints">src/MissionManager/UnitTest/MissionPlanner.waypoints</file>
<file alias="OldFileFormat.mission">src/MissionManager/UnitTest/OldFileFormat.mission</file> <file alias="OldFileFormat.mission">src/MissionManager/UnitTest/OldFileFormat.mission</file>
<file alias="PolygonAreaTest.kml">src/MissionManager/UnitTest/PolygonAreaTest.kml</file> <file alias="PolygonAreaTest.kml">src/MissionManager/UnitTest/PolygonAreaTest.kml</file>
<file alias="PolygonGood.kml">src/MissionManager/UnitTest/PolygonGood.kml</file> <file alias="PolygonGood.kml">src/MissionManager/UnitTest/PolygonGood.kml</file>
<file alias="PolygonMissingNode.kml">src/MissionManager/UnitTest/PolygonMissingNode.kml</file> <file alias="PolygonMissingNode.kml">src/MissionManager/UnitTest/PolygonMissingNode.kml</file>
<file alias="PolygonBadXml.kml">src/MissionManager/UnitTest/PolygonBadXml.kml</file> <file alias="PolygonBadXml.kml">src/MissionManager/UnitTest/PolygonBadXml.kml</file>
<file alias="PolygonBadCoordinatesNode.kml">src/MissionManager/UnitTest/PolygonBadCoordinatesNode.kml</file> <file alias="PolygonBadCoordinatesNode.kml">src/MissionManager/UnitTest/PolygonBadCoordinatesNode.kml</file>
<file alias="MockLinkOptionsDlg.qml">src/comm/MockLinkOptionsDlg.qml</file>
</qresource> </qresource>
<qresource prefix="/"/>
</RCC> </RCC>
This diff is collapsed.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* \file SDL.h
*
* Main include header for the SDL library
*/
#ifndef SDL_h_
#define SDL_h_
#include "SDL_main.h"
#include "SDL_stdinc.h"
#include "SDL_assert.h"
#include "SDL_atomic.h"
#include "SDL_audio.h"
#include "SDL_clipboard.h"
#include "SDL_cpuinfo.h"
#include "SDL_endian.h"
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_filesystem.h"
#include "SDL_gamecontroller.h"
#include "SDL_haptic.h"
#include "SDL_hints.h"
#include "SDL_joystick.h"
#include "SDL_loadso.h"
#include "SDL_log.h"
#include "SDL_messagebox.h"
#include "SDL_mutex.h"
#include "SDL_power.h"
#include "SDL_render.h"
#include "SDL_rwops.h"
#include "SDL_sensor.h"
#include "SDL_shape.h"
#include "SDL_system.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "SDL_version.h"
#include "SDL_video.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* As of version 0.5, SDL is loaded dynamically into the application */
/**
* \name SDL_INIT_*
*
* These are the flags which may be passed to SDL_Init(). You should
* specify the subsystems which you will be using in your application.
*/
/* @{ */
#define SDL_INIT_TIMER 0x00000001u
#define SDL_INIT_AUDIO 0x00000010u
#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
#define SDL_INIT_JOYSTICK 0x00000200u /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
#define SDL_INIT_HAPTIC 0x00001000u
#define SDL_INIT_GAMECONTROLLER 0x00002000u /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
#define SDL_INIT_EVENTS 0x00004000u
#define SDL_INIT_SENSOR 0x00008000u
#define SDL_INIT_NOPARACHUTE 0x00100000u /**< compatibility; this flag is ignored. */
#define SDL_INIT_EVERYTHING ( \
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR \
)
/* @} */
/**
* This function initializes the subsystems specified by \c flags
*/
extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags);
/**
* This function initializes specific SDL subsystems
*
* Subsystem initialization is ref-counted, you must call
* SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly
* shutdown a subsystem manually (or call SDL_Quit() to force shutdown).
* If a subsystem is already loaded then this call will
* increase the ref-count and return.
*/
extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
/**
* This function cleans up specific SDL subsystems
*/
extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
/**
* This function returns a mask of the specified subsystems which have
* previously been initialized.
*
* If \c flags is 0, it returns a mask of all initialized subsystems.
*/
extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);
/**
* This function cleans up all initialized subsystems. You should
* call it upon all exit conditions.
*/
extern DECLSPEC void SDLCALL SDL_Quit(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* SDL_h_ */
/* vi: set ts=4 sw=4 expandtab: */
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* \file SDL_bits.h
*
* Functions for fiddling with bits and bitmasks.
*/
#ifndef SDL_bits_h_
#define SDL_bits_h_
#include "SDL_stdinc.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* \file SDL_bits.h
*/
/**
* Get the index of the most significant bit. Result is undefined when called
* with 0. This operation can also be stated as "count leading zeroes" and
* "log base 2".
*
* \return Index of the most significant bit, or -1 if the value is 0.
*/
#if defined(__WATCOMC__) && defined(__386__)
extern _inline int _SDL_clz_watcom (Uint32);
#pragma aux _SDL_clz_watcom = \
"bsr eax, eax" \
"xor eax, 31" \
parm [eax] nomemory \
value [eax] \
modify exact [eax] nomemory;
#endif
SDL_FORCE_INLINE int
SDL_MostSignificantBitIndex32(Uint32 x)
{
#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
/* Count Leading Zeroes builtin in GCC.
* http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gcc/Other-Builtins.html
*/
if (x == 0) {
return -1;
}
return 31 - __builtin_clz(x);
#elif defined(__WATCOMC__) && defined(__386__)
if (x == 0) {
return -1;
}
return 31 - _SDL_clz_watcom(x);
#else
/* Based off of Bit Twiddling Hacks by Sean Eron Anderson
* <seander@cs.stanford.edu>, released in the public domain.
* http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
*/
const Uint32 b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
const int S[] = {1, 2, 4, 8, 16};
int msbIndex = 0;
int i;
if (x == 0) {
return -1;
}
for (i = 4; i >= 0; i--)
{
if (x & b[i])
{
x >>= S[i];
msbIndex |= S[i];
}
}
return msbIndex;
#endif
}
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"
#endif /* SDL_bits_h_ */
/* vi: set ts=4 sw=4 expandtab: */