1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

chore(cmake): let CMake choose which platform dependent code to compile

Macros can be hard to manipulate and vary among different compilers and
platforms. For example, GNU Hurd has `__MACH__` defined but not
`__APPLE__`.

Let CMake choose them during configuration.
This commit is contained in:
yangfl 2018-12-03 15:59:31 +08:00
parent ec9d9850bf
commit 6d0885f396
12 changed files with 20 additions and 45 deletions

View File

@ -524,17 +524,27 @@ if (PLATFORM_EXTENSIONS)
src/platform/autorun.h src/platform/autorun.h
src/platform/capslock.h src/platform/capslock.h
src/platform/timer.h src/platform/timer.h
src/platform/autorun_osx.cpp
src/platform/autorun_win.cpp
src/platform/autorun_xdg.cpp
src/platform/capslock_osx.cpp
src/platform/capslock_win.cpp
src/platform/capslock_x11.cpp
src/platform/timer_osx.cpp
src/platform/timer_win.cpp
src/platform/timer_x11.cpp
src/platform/x11_display.cpp
) )
if (WIN32)
set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES}
src/platform/autorun_win.cpp
src/platform/capslock_win.cpp
src/platform/timer_win.cpp
)
elseif (${X11_EXT})
set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES}
src/platform/autorun_xdg.cpp
src/platform/capslock_x11.cpp
src/platform/timer_x11.cpp
src/platform/x11_display.cpp
)
elseif (${APPLE_EXT})
set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES}
src/platform/autorun_osx.cpp
src/platform/capslock_osx.cpp
src/platform/timer_osx.cpp
)
endif()
endif() endif()
add_definitions(-DQT_MESSAGELOGCONTEXT=1) add_definitions(-DQT_MESSAGELOGCONTEXT=1)

View File

@ -17,7 +17,6 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>. along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/ */
#if defined(__APPLE__) && defined(__MACH__)
#include "src/platform/autorun.h" #include "src/platform/autorun.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDir> #include <QDir>
@ -48,5 +47,3 @@ bool Platform::getAutorun()
{ {
return state; return state;
} }
#endif // defined(__APPLE__) && defined(__MACH__)

View File

@ -18,7 +18,6 @@
*/ */
#include <QApplication> #include <QApplication>
#ifdef Q_OS_WIN32
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/platform/autorun.h" #include "src/platform/autorun.h"
#include <string> #include <string>
@ -101,5 +100,3 @@ bool Platform::getAutorun()
RegCloseKey(key); RegCloseKey(key);
return result; return result;
} }
#endif // Q_OS_WIN32

View File

@ -18,7 +18,6 @@
*/ */
#include <QApplication> #include <QApplication>
#if defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/platform/autorun.h" #include "src/platform/autorun.h"
#include <QDir> #include <QDir>
@ -69,5 +68,3 @@ bool Platform::getAutorun()
{ {
return QFile(getAutostartFilePath(getAutostartDirPath())).exists(); return QFile(getAutostartFilePath(getAutostartDirPath())).exists();
} }
#endif // defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)

View File

@ -18,7 +18,6 @@
*/ */
#include <QtCore/qsystemdetection.h> #include <QtCore/qsystemdetection.h>
#if defined(__APPLE__) && defined(__MACH__)
#include "src/platform/capslock.h" #include "src/platform/capslock.h"
// TODO: Implement for osx // TODO: Implement for osx
@ -26,5 +25,3 @@ bool Platform::capsLockEnabled()
{ {
return false; return false;
} }
#endif // defined(__APPLE__) && defined(__MACH__)

View File

@ -18,7 +18,6 @@
*/ */
#include <QtCore/qsystemdetection.h> #include <QtCore/qsystemdetection.h>
#ifdef Q_OS_WIN32
#include "src/platform/capslock.h" #include "src/platform/capslock.h"
#include <windows.h> #include <windows.h>
@ -26,5 +25,3 @@ bool Platform::capsLockEnabled()
{ {
return GetKeyState(VK_CAPITAL) == 1; return GetKeyState(VK_CAPITAL) == 1;
} }
#endif // Q_OS_WIN32

View File

@ -18,7 +18,6 @@
*/ */
#include <QtCore/qsystemdetection.h> #include <QtCore/qsystemdetection.h>
#if defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
#include "src/platform/capslock.h" #include "src/platform/capslock.h"
#include "src/platform/x11_display.h" #include "src/platform/x11_display.h"
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
@ -39,6 +38,3 @@ bool Platform::capsLockEnabled()
X11Display::unlock(); X11Display::unlock();
return caps_state; return caps_state;
} }
#endif // defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)

View File

@ -24,7 +24,6 @@
*/ */
#include <QtCore/qsystemdetection.h> #include <QtCore/qsystemdetection.h>
#if defined(__APPLE__) && defined(__MACH__)
#include "src/platform/timer.h" #include "src/platform/timer.h"
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h> #include <IOKit/IOKitLib.h>
@ -50,5 +49,3 @@ uint32_t Platform::getIdleTime()
return idleTime_ns / 1000000; return idleTime_ns / 1000000;
} }
#endif // defined(__APPLE__) && defined(__MACH__)

View File

@ -18,7 +18,6 @@
*/ */
#include <QtCore/qsystemdetection.h> #include <QtCore/qsystemdetection.h>
#ifdef Q_OS_WIN32
#include "src/platform/timer.h" #include "src/platform/timer.h"
#include <windows.h> #include <windows.h>
@ -30,5 +29,3 @@ uint32_t Platform::getIdleTime()
return GetTickCount() - info.dwTime; return GetTickCount() - info.dwTime;
return 0; return 0;
} }
#endif // Q_OS_WIN32

View File

@ -16,7 +16,6 @@
*/ */
#include <QtCore/qsystemdetection.h> #include <QtCore/qsystemdetection.h>
#if defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
#include "src/platform/timer.h" #include "src/platform/timer.h"
#include "src/platform/x11_display.h" #include "src/platform/x11_display.h"
#include <QDebug> #include <QDebug>
@ -47,5 +46,3 @@ uint32_t Platform::getIdleTime()
X11Display::unlock(); X11Display::unlock();
return idleTime; return idleTime;
} }
#endif // Q_OS_UNIX

View File

@ -18,7 +18,6 @@
*/ */
#include <QtCore/qsystemdetection.h> #include <QtCore/qsystemdetection.h>
#if defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
#include "src/platform/x11_display.h" #include "src/platform/x11_display.h"
#include <QMutex> #include <QMutex>
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -60,5 +59,3 @@ void X11Display::unlock()
X11DisplayPrivate::getSingleInstance().mutex.unlock(); X11DisplayPrivate::getSingleInstance().mutex.unlock();
} }
} }
#endif // Q_OS_UNIX && !defined(__APPLE__) && !defined(__MACH__)

View File

@ -22,8 +22,6 @@
#ifndef PLATFORM_X11_DISPLAY_H #ifndef PLATFORM_X11_DISPLAY_H
#define PLATFORM_X11_DISPLAY_H #define PLATFORM_X11_DISPLAY_H
#if defined(Q_OS_UNIX) && !defined(__APPLE__) && !defined(__MACH__)
typedef struct _XDisplay Display; typedef struct _XDisplay Display;
namespace Platform { namespace Platform {
@ -35,8 +33,6 @@ void unlock();
} }
#endif // Q_OS_UNIX && !defined(__APPLE__) && !defined(__MACH__)
#endif // PLATFORM_X11_DISPLAY_H #endif // PLATFORM_X11_DISPLAY_H
#endif // QTOX_PLATFORM_EXT #endif // QTOX_PLATFORM_EXT