Add OS native interface lib, with objective-c++ interface to Mac Cocoa libraries

This commit is contained in:
Larry Shaffer 2014-01-16 01:49:15 -07:00 committed by Nyall Dawson
parent f8f7d60cf0
commit f6bd7b3b58
17 changed files with 559 additions and 11 deletions

View File

@ -494,8 +494,6 @@ ELSE (WIN32)
ELSE ()
SET (OSX_HAVE_LOADERPATH 0)
ENDIF ()
#this will define ${APP_SERVICES_LIBRARY}
FIND_LIBRARY(APP_SERVICES_LIBRARY ApplicationServices )
SET (DEFAULT_BIN_SUBDIR bin)
SET (QGIS_BIN_SUBDIR_REV ..)
@ -750,6 +748,11 @@ ADD_CUSTOM_TARGET(version ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/qgsversion.h)
#TEST_DATA_DIR is also used by QgsRenderChecker currently in core
SET (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata")
SET(USE_NATIVE_LIB FALSE)
IF(APPLE)
SET(USE_NATIVE_LIB TRUE)
ENDIF(APPLE)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(doc)
ADD_SUBDIRECTORY(images)

View File

@ -1,3 +1,7 @@
IF(USE_NATIVE_LIB)
ADD_SUBDIRECTORY(native)
ENDIF(USE_NATIVE_LIB)
ADD_SUBDIRECTORY(core)
ADD_SUBDIRECTORY(analysis)
ADD_SUBDIRECTORY(ui)

View File

@ -529,12 +529,18 @@ INCLUDE_DIRECTORIES(SYSTEM
${QWTPOLAR_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
)
)
IF(ENABLE_MODELTEST)
INCLUDE_DIRECTORIES(../../tests/qt_modeltest)
ENDIF(ENABLE_MODELTEST)
IF (USE_NATIVE_LIB)
IF(APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
ENDIF(APPLE)
ENDIF(USE_NATIVE_LIB)
IF (ANDROID)
INCLUDE_DIRECTORIES(SYSTEM ${ANDROID_NDK_TOOLCHAIN_ROOT}/sysroot/usr/include)
ENDIF (ANDROID)
@ -586,6 +592,10 @@ IF (APPLE)
TARGET_LINK_LIBRARIES(qgis_app ${APP_SERVICES_LIBRARY})
ENDIF(APPLE)
IF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(qgis_app qgis_native)
ENDIF(USE_NATIVE_LIB)
if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
SET_TARGET_PROPERTIES(qgis_app PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
ENDIF(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
@ -605,9 +615,11 @@ IF(WIN32)
TARGET_LINK_LIBRARIES(qgis_app DbgHelp Qt5::WinExtras)
ENDIF(WIN32)
IF (APPLE)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} ${APP_SERVICES_LIBRARY})
IF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} qgis_native)
ENDIF(USE_NATIVE_LIB)
IF (APPLE)
SET_TARGET_PROPERTIES(${QGIS_APP_NAME} PROPERTIES
INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
INSTALL_RPATH_USE_LINK_PATH true

View File

@ -101,6 +101,12 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#ifdef Q_OS_MACX
#include <ApplicationServices/ApplicationServices.h>
// Virtual interfaces to Cocoa objective-c frameworks/classes/calls
// cocoainitializer is to handle objective-c garbage collection
// see: http://el-tramo.be/blog/mixing-cocoa-and-qt/
//#include "cocoainitializer.h"
#include "qgsmacappkit.h"
// check macro breaks QItemDelegate
#ifdef check
#undef check
@ -6120,9 +6126,10 @@ void QgisApp::bringAllToFront()
{
#ifdef Q_OS_MAC
// Bring forward all open windows while maintaining layering order
ProcessSerialNumber psn;
GetCurrentProcess( &psn );
SetFrontProcess( &psn );
// method valid for Mac OS X >= 10.6
QgsNSRunningApplication* nsrapp = new QgsNSRunningApplication();
nsrapp->currentAppActivateIgnoringOtherApps();
delete nsrapp;
#endif
}

View File

@ -1044,6 +1044,12 @@ INCLUDE_DIRECTORIES(SYSTEM
${QTKEYCHAIN_INCLUDE_DIR}
)
IF(USE_NATIVE_LIB)
IF(APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
ENDIF(APPLE)
ENDIF(USE_NATIVE_LIB)
#for PAL classes
IF (WIN32)
ADD_DEFINITIONS("-D_HAVE_WINDOWS_H_")
@ -1112,9 +1118,9 @@ IF (WIN32)
TARGET_LINK_LIBRARIES(qgis_core wsock32 ${SETUPAPI_LIBRARY} DbgHelp)
ENDIF (WIN32)
IF(APPLE)
TARGET_LINK_LIBRARIES(qgis_core "-framework CoreFoundation -framework IOKit")
ENDIF(APPLE)
IF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(qgis_core qgis_native)
ENDIF(USE_NATIVE_LIB)
IF (NOT WITH_INTERNAL_QEXTSERIALPORT)
TARGET_LINK_LIBRARIES(qgis_core ${QEXTSERIALPORT_LIBRARY})

116
src/native/CMakeLists.txt Normal file
View File

@ -0,0 +1,116 @@
#############################################################
# locate native libs
SET(NATIVE_LINK_LIBS)
IF(APPLE)
SET(APPLE_LIB_LIST ApplicationServices CoreFoundation IOKit AppKit)
FOREACH(_lib ${APPLE_LIB_LIST})
STRING(TOUPPER ${_lib} _lib_var)
# prefer /System/Library/Frameworks, in case CMAKE_FIND_FRAMEWORK=LAST, etc.
FIND_LIBRARY(APPLE_${_lib_var}_LIBRARY
NAMES ${_lib}
PATHS /System/Library/Frameworks
NO_DEFAULT_PATH
)
# if not found, drop back to standard find paths
FIND_LIBRARY(APPLE_${_lib_var}_LIBRARY ${_lib})
IF(NOT APPLE_${_lib_var}_LIBRARY)
MESSAGE(FATAL_ERROR "Couldn't find Apple's '${_lib}' framework or library")
ENDIF(NOT APPLE_${_lib_var}_LIBRARY)
LIST(APPEND NATIVE_LINK_LIBS "-framework ${_lib}")
ENDFOREACH(_lib ${APPLE_LIB_LIST})
ENDIF(APPLE)
#############################################################
# sources
SET(QGIS_CORE_SRCS)
IF(APPLE)
SET(QGIS_APP_OBJC_SRCS
mac/cocoainitializer.mm
mac/qgsmacappkit.mm
)
SET_SOURCE_FILES_PROPERTIES(${QGIS_APP_OBJC_SRCS} PROPERTIES COMPILE_FLAGS "-x objective-c++")
SET(QGIS_CORE_SRCS ${QGIS_CORE_SRCS}
${QGIS_APP_OBJC_SRCS}
mac/qgsmacnative.cpp
)
ENDIF(APPLE)
SET(QGIS_CORE_MOC_HDRS)
QT4_WRAP_CPP(QGIS_CORE_MOC_SRCS ${QGIS_CORE_MOC_HDRS})
# install headers
IF(APPLE)
SET (QGIS_CORE_HDRS ${QGIS_CORE_HDRS}
mac/qgsmacnative.h
mac/cocoainitializer.h
mac/qgsmacappkit.h
)
ENDIF(APPLE)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
)
IF(APPLE)
INCLUDE_DIRECTORIES(mac)
ENDIF(APPLE)
# Test data dir for QgsRenderChecker
ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")
#############################################################
# qgis_native library
ADD_LIBRARY(qgis_native SHARED ${QGIS_CORE_SRCS} ${QGIS_CORE_MOC_SRCS} ${QGIS_CORE_HDRS} ${QGIS_CORE_MOC_HDRS})
IF(NOT APPLE)
INSTALL(FILES ${QGIS_CORE_HDRS} ${QGIS_CORE_MOC_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
ELSE(NOT APPLE)
SET_TARGET_PROPERTIES(qgis_native PROPERTIES
CLEAN_DIRECT_OUTPUT 1
FRAMEWORK 1
FRAMEWORK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_SOURCE_DIR}/mac/framework.info.plist.in"
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${COMPLETE_VERSION}
MACOSX_FRAMEWORK_IDENTIFIER org.qgis.qgis2_native
BUILD_WITH_INSTALL_RPATH TRUE
PUBLIC_HEADER "${QGIS_CORE_HDRS};${QGIS_CORE_MOC_HDRS}"
LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
)
ENDIF(NOT APPLE)
#generate unversioned libs for android
IF(NOT ANDROID)
SET_TARGET_PROPERTIES(qgis_native PROPERTIES
VERSION ${COMPLETE_VERSION}
SOVERSION ${COMPLETE_VERSION}
)
ENDIF(NOT ANDROID)
TARGET_LINK_LIBRARIES(qgis_native "${NATIVE_LINK_LIBS}")
# install
INSTALL(TARGETS qgis_native
RUNTIME DESTINATION ${QGIS_BIN_DIR}
LIBRARY DESTINATION ${QGIS_LIB_DIR}
ARCHIVE DESTINATION ${QGIS_LIB_DIR}
FRAMEWORK DESTINATION ${QGIS_FW_SUBDIR}
PUBLIC_HEADER DESTINATION ${QGIS_INCLUDE_DIR})
# Mac dev frameworks
IF (APPLE AND QGIS_MACAPP_INSTALL_DEV)
INSTALL(TARGETS qgis_native FRAMEWORK DESTINATION ${QGIS_MACAPP_DEV_PREFIX})
INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -id \"${QGIS_MACAPP_DEV_PREFIX}/qgis_native.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_native\" \"$ENV{DESTDIR}${QGIS_MACAPP_DEV_PREFIX}/qgis_native.framework/qgis_native\")")
ENDIF (APPLE AND QGIS_MACAPP_INSTALL_DEV)

23
src/native/README.md Normal file
View File

@ -0,0 +1,23 @@
README for qgis_native lib
==========================
This library is intended to offer abstraction to the host OS's underlying public
interfaces. This is useful for OSes that provide interfaces in languages other
than C/C++, or for grouping calls to OS-specific code so that it only needs to
be updated in one place in the source tree. It is advisable to leverage existing
functions provided by Qt, rather than rely upon OS-specific code, unless such
code extends the application to provide a better OS-specific user experience or
solve a problem.
Example
-------
As of Mac OS X 10.9 (Mavericks) many system public API calls to Carbon libraries
(based upon C) have been deprecated in favor of modern Cocoa libraries (written
in Objective-C), which can no longer be directly called from C++. Coalescing
and mixing these new calls in a library, using Objective-C++ allows not only
access to the Apple system Objective-C libraries and frameworks, but also those
from third-parties, like the auto-updating Sparkle.framework.
See also: http://el-tramo.be/blog/mixing-cocoa-and-qt/
http://sparkle.andymatuschak.org/

View File

@ -0,0 +1,54 @@
/***************************************************************************
cocoaInitializer.h - used to enable Cocoas memory management
-------------------
copyright : (C) 2008 by Remko Troncon
email : remco at el-tramo dot be
url : http://el-tramo.be/blog/mixing-cocoa-and-qt/
***************************************************************************/
/***************************************************************************
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
(1) Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
(2) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
(3)The name of the author may not be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
#ifndef COCOAINITIALIZER_H
#define COCOAINITIALIZER_H
class CocoaInitializer
{
public:
CocoaInitializer();
~CocoaInitializer();
private:
class Private;
Private* d;
};
#endif // COCOAINITIALIZER_H

View File

@ -0,0 +1,61 @@
/***************************************************************************
cocoaInitializer.mm - used to enable Cocoas memory management
-------------------
copyright : (C) 2008 by Remko Troncon
email : remco at el-tramo dot be
url : http://el-tramo.be/blog/mixing-cocoa-and-qt/
***************************************************************************/
/***************************************************************************
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
(1) Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
(2) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
(3)The name of the author may not be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
#include "CocoaInitializer.h"
#include <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>
class CocoaInitializer::Private
{
public:
NSAutoreleasePool* autoReleasePool_;
};
CocoaInitializer::CocoaInitializer()
{
d = new CocoaInitializer::Private();
NSApplicationLoad();
d->autoReleasePool_ = [[NSAutoreleasePool alloc] init];
}
CocoaInitializer::~CocoaInitializer()
{
[d->autoReleasePool_ release];
delete d;
}

View File

@ -0,0 +1,37 @@
/***************************************************************************
qgsmacappkit.h - interface to Mac objective-c AppKit.framework
-------------------
begin : January 2014
copyright : (C) 2014 by Larry Shaffer
email : larrys at dakotacarto dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSMACAPPKIT_H
#define QGSMACAPPKIT_H
#include "qgsmacnative.h"
class QgsNSRunningApplication : public QgsMacAppKit
{
public:
QgsNSRunningApplication();
~QgsNSRunningApplication();
const char* currentAppLocalizedName();
void currentAppActivateIgnoringOtherApps();
private:
class Private;
Private* d;
};
#endif // QGSMACAPPKIT_H

View File

@ -0,0 +1,51 @@
/***************************************************************************
qgsmacappkit.mm - interface to Mac objective-c AppKit.framework
-------------------
begin : January 2014
copyright : (C) 2014 by Larry Shaffer
email : larrys at dakotacarto dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsmacappkit.h"
#include <Cocoa/Cocoa.h>
class QgsNSRunningApplication::Private
{
public:
// NSObject *obj;
};
QgsNSRunningApplication::QgsNSRunningApplication()
{
// d = new Private;
// d->obj = [NSObject someFunction];
}
QgsNSRunningApplication::~QgsNSRunningApplication()
{
// [d->obj release];
// delete d;
// d = 0;
}
const char* QgsNSRunningApplication::currentAppLocalizedName()
{
return [[[NSRunningApplication currentApplication] localizedName] UTF8String];
}
void QgsNSRunningApplication::currentAppActivateIgnoringOtherApps()
{
// valid for Mac OS X >= 10.6
[[NSRunningApplication currentApplication] activateWithOptions:
(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
}

View File

@ -0,0 +1,22 @@
/***************************************************************************
qgsmacnative.cpp - abstracted interface to native Mac objective-c
-------------------
begin : January 2014
copyright : (C) 2014 by Larry Shaffer
email : larrys at dakotacarto dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsmacnative.h"
QgsMacAppKit::~QgsMacAppKit()
{
}

View File

@ -0,0 +1,31 @@
/***************************************************************************
qgsmacnative.h - abstracted interface to native Mac objective-c
-------------------
begin : January 2014
copyright : (C) 2014 by Larry Shaffer
email : larrys at dakotacarto dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSMACNATIVE_H
#define QGSMACNATIVE_H
class QgsMacAppKit
{
public:
virtual ~QgsMacAppKit();
// NSRunningApplication interface
virtual const char* currentAppLocalizedName() = 0;
virtual void currentAppActivateIgnoringOtherApps() = 0;
};
#endif // QGSMACNATIVE_H

View File

@ -36,6 +36,9 @@ IF (ENABLE_TESTS)
IF (WITH_DESKTOP)
ADD_SUBDIRECTORY(app)
ENDIF (WITH_DESKTOP)
IF(USE_NATIVE_LIB)
ADD_SUBDIRECTORY(native)
ENDIF(USE_NATIVE_LIB)
IF (WITH_BINDINGS)
ADD_SUBDIRECTORY(python)
ENDIF (WITH_BINDINGS)

View File

@ -37,6 +37,12 @@ INCLUDE_DIRECTORIES(SYSTEM
${QSCINTILLA_INCLUDE_DIR}
)
IF(USE_NATIVE_LIB)
IF(APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
ENDIF(APPLE)
ENDIF(USE_NATIVE_LIB)
#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
@ -76,6 +82,10 @@ MACRO (ADD_QGIS_TEST testname testsrc)
TARGET_LINK_LIBRARIES(qgis_${testname} ${APP_SERVICES_LIBRARY} )
ENDIF(APPLE)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
IF(USE_NATIVE_LIB)
TARGET_LINK_LIBRARIES(qgis_${testname} qgis_native)
ENDIF(USE_NATIVE_LIB)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
#SET_TARGET_PROPERTIES(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )

View File

@ -0,0 +1,68 @@
# Standard includes and utils to compile into all tests.
#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${QT_INCLUDE_DIR}
)
IF(APPLE)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/native/mac)
ENDIF(APPLE)
#############################################################
# Compiler defines
# This define is used for tests that need to locate the test
# data under tests/testdata in the qgis source tree.
# the TEST_DATA_DIR variable is set in the top level CMakeLists.txt
ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")
ADD_DEFINITIONS(-DINSTALL_PREFIX="\\"${CMAKE_INSTALL_PREFIX}\\"")
#############################################################
# libraries
# because of htonl
IF (WIN32)
SET(PLATFORM_LIBRARIES wsock32)
ENDIF (WIN32)
# Since the tests are not actually installed, but rather
# run directly from the build/src/tests dir we need to
# ensure the qgis libs can be found.
IF (APPLE)
# For Mac OS X, the executable must be at the root of the bundle's executable folder
# SET (CMAKE_INSTALL_NAME_DIR @executable_path/../../../src/core)
ENDIF (APPLE)
#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time
#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree
MACRO (ADD_QGIS_TEST testname testsrc)
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
SET(qgis_${testname}_MOC_CPPS ${testsrc})
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
TARGET_LINK_LIBRARIES(qgis_${testname}
${QT_QTCORE_LIBRARY}
${QT_QTTEST_LIBRARY}
qgis_app
qgis_native)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
ENDMACRO (ADD_QGIS_TEST)
#############################################################
# Tests:
ADD_QGIS_TEST(macnativetest testqgsmacnative.cpp)

View File

@ -0,0 +1,40 @@
/***************************************************************************
testqgsmacnative.cpp
--------------------------------------
Date : January 2014
Copyright : (C) 2014 by Larry Shaffer
Email : larrys at dakotacarto dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QtTest>
#include <QObject>
#include <QString>
//header for class being tested
#include <qgsmacappkit.h>
class TestQgsMacNative: public QObject
{
Q_OBJECT
private slots:
void testGetRunningAppName();
};
void TestQgsMacNative::testGetRunningAppName()
{
QgsNSRunningApplication* nsrapp = new QgsNSRunningApplication();
QString nsrapp_name( nsrapp->currentAppLocalizedName() );
delete nsrapp;
QCOMPARE( QString( "qgis_macnativetest" ), nsrapp_name.trimmed() );
}
QTEST_MAIN( TestQgsMacNative )
#include "moc_testqgsmacnative.cxx"