Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #4558 from nyalldawson/native-lib-mac
Add OS native interface lib, with objective-c++ interface to Mac Cocoa libraries, v3
- Loading branch information
Showing
22 changed files
with
570 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
ADD_SUBDIRECTORY(native) | ||
|
||
ADD_SUBDIRECTORY(core) | ||
ADD_SUBDIRECTORY(analysis) | ||
ADD_SUBDIRECTORY(ui) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
############################################################# | ||
# 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_NATIVE_SRCS | ||
qgsnative.cpp | ||
) | ||
|
||
IF(APPLE) | ||
SET(QGIS_APP_OBJC_SRCS | ||
mac/cocoainitializer.mm | ||
mac/qgsmacnative.mm | ||
) | ||
|
||
SET_SOURCE_FILES_PROPERTIES(${QGIS_APP_OBJC_SRCS} PROPERTIES COMPILE_FLAGS "-x objective-c++") | ||
|
||
SET(QGIS_NATIVE_SRCS ${QGIS_NATIVE_SRCS} | ||
${QGIS_APP_OBJC_SRCS} | ||
) | ||
ENDIF(APPLE) | ||
|
||
SET(QGIS_NATIVE_HDRS | ||
qgsnative.h | ||
) | ||
|
||
# install headers | ||
|
||
IF(APPLE) | ||
SET (QGIS_NATIVE_HDRS ${QGIS_NATIVE_HDRS} | ||
mac/qgsmacnative.h | ||
mac/cocoainitializer.h | ||
) | ||
ENDIF(APPLE) | ||
|
||
INCLUDE_DIRECTORIES( | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
############################################################# | ||
# qgis_native library | ||
|
||
ADD_LIBRARY(qgis_native SHARED ${QGIS_NATIVE_SRCS} ${QGIS_NATIVE_HDRS}) | ||
SET_PROPERTY(TARGET qgis_native PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
|
||
GENERATE_EXPORT_HEADER( | ||
qgis_native | ||
BASE_NAME NATIVE | ||
EXPORT_FILE_NAME qgis_native.h | ||
) | ||
|
||
SET(QGIS_NATIVE_HDRS ${QGIS_NATIVE_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/qgis_native.h) | ||
|
||
IF(NOT APPLE) | ||
INSTALL(FILES ${QGIS_NATIVE_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_NATIVE_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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
Oops, something went wrong.