diff --git a/CMakeLists.txt b/CMakeLists.txt
index c79744b3..6e83370d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,10 +13,13 @@ set(LIB_PROJECT_NAME "${PROJECT_NAME}_lib")
set(TEST_PROJECT_NAME "${PROJECT_NAME}_test")
if (WIN32)
- set(PLATFORM_INCLUDES "#include \"includesWindows.h\"")
+ set(PLATFORM_INCLUDE "includesWindows.h")
LINK_DIRECTORIES($ENV{VLD_DIR}/lib/Win32) # this adds the library path for VLD, must be done before the project target is created
-endif()
-
+elseif (APPLE)
+ set(PLATFORM_INCLUDE "includesMac.h")
+else ()
+ set(PLATFORM_INCLUDE "includesDefault.h")
+endif ()
# Settings ---------------------------------------------------------------------
@@ -42,9 +45,7 @@ set(Boost_USE_MULTITHREAD ON)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_LIBRARYDIR $ENV{BOOST_155_DIR})
-find_package( Boost 1.55 COMPONENTS system filesystem REQUIRED )
-
-message("${BOOST_LIBRARYDIR}")
+find_package(Boost 1.55 COMPONENTS system filesystem REQUIRED)
# Lib --------------------------------------------------------------------------
@@ -123,12 +124,54 @@ qt5_use_modules(${APP_PROJECT_NAME} Widgets)
# configure platform specific include file
configure_file(
- "${PROJECT_SOURCE_DIR}/src/app/includes.h.in"
+ "${PROJECT_SOURCE_DIR}/src/app/platform_includes/includes.h.in"
"${PROJECT_SOURCE_DIR}/build/src/app/includes.h"
)
+# add platform specific libraries
+if (APPLE)
+ find_library(CORE_FOUNDATION CoreFoundation)
+ target_link_libraries(${APP_PROJECT_NAME} ${CORE_FOUNDATION})
+endif ()
+
set(CMAKE_AUTOMOC OFF)
+# MacOSX Bundle ----------------------------------------------------------------
+
+if (APPLE)
+
+ set(MACOSX_BUNDLE_NAME ${PROJECT_NAME})
+ set(MACOSX_BINARY_NAME ${APP_PROJECT_NAME})
+
+ set(MACOSX_DYNAMIC_LIBRARIES ${Boost_LIBRARIES})
+ string(REPLACE ";" " " MACOSX_DYNAMIC_LIBRARIES "${MACOSX_DYNAMIC_LIBRARIES}")
+
+ get_property(QT_CORE_PATH TARGET ${Qt5Core_LIBRARIES} PROPERTY LOCATION)
+ get_filename_component(QT_CORE_PATH ${QT_CORE_PATH} REALPATH)
+
+ get_property(QT_GUI_PATH TARGET ${Qt5Gui_LIBRARIES} PROPERTY LOCATION)
+ get_filename_component(QT_GUI_PATH ${QT_GUI_PATH} REALPATH)
+
+ get_property(QT_WIDGETS_PATH TARGET ${Qt5Widgets_LIBRARIES} PROPERTY LOCATION)
+ get_filename_component(QT_WIDGETS_PATH ${QT_WIDGETS_PATH} REALPATH)
+
+ list(APPEND MACOSX_FRAMEWORKS ${QT_CORE_PATH} ${QT_GUI_PATH} ${QT_WIDGETS_PATH})
+ string(REPLACE ";" " " MACOSX_FRAMEWORKS "${MACOSX_FRAMEWORKS}")
+
+ configure_file(
+ ${PROJECT_SOURCE_DIR}/setup/MacOSX/bundle_install.sh.in
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bundle_install.sh
+ @ONLY
+ )
+
+ configure_file(
+ ${PROJECT_SOURCE_DIR}/setup/MacOSX/Info.plist.in
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bundle_info.plist
+ @ONLY
+ )
+
+endif ()
+
# CxxTest ----------------------------------------------------------------------
if (UNIX)
@@ -200,5 +243,4 @@ if (WIN32)
include_directories($ENV{VLD_DIR}/include)
-endif()
-
+endif ()
diff --git a/setup/MacOSX/Info.plist.in b/setup/MacOSX/Info.plist.in
new file mode 100644
index 00000000..73f27e6f
--- /dev/null
+++ b/setup/MacOSX/Info.plist.in
@@ -0,0 +1,38 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleExecutable
+ @MACOSX_BINARY_NAME@
+ CFBundleGetInfoString
+
+ CFBundleIconFile
+
+ CFBundleIdentifier
+ at.ac.fh-salzburg.masterproject
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleLongVersionString
+
+ CFBundleName
+
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+
+ CFBundleSignature
+ ????
+ CFBundleVersion
+
+ CSResourcesFileMapped
+
+ LSRequiresCarbon
+
+ NSHumanReadableCopyright
+
+ NSHighResolutionCapable
+
+
+
diff --git a/setup/MacOSX/bundle_install.sh.in b/setup/MacOSX/bundle_install.sh.in
new file mode 100755
index 00000000..5cd39939
--- /dev/null
+++ b/setup/MacOSX/bundle_install.sh.in
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+ABORT="\033[31mAbort:\033[00m"
+SUCCESS="\033[32mSuccess:\033[00m"
+INFO="\033[33mInfo:\033[00m"
+
+MY_PATH=`dirname "$0"`
+cd $MY_PATH
+
+echo -e $INFO "Creating app bundle for MacOSX."
+
+BUNDLE_NAME="@MACOSX_BUNDLE_NAME@"
+APP_NAME="@MACOSX_BINARY_NAME@"
+DYNLIB_PATHS=(@MACOSX_DYNAMIC_LIBRARIES@)
+FRAMEWORK_PATHS=(@MACOSX_FRAMEWORKS@)
+
+if [ ! -x "$APP_NAME" ]
+then
+ echo -e $ABORT "Executable $APP_NAME does not exist."
+ exit 1
+fi
+
+if [ ! -e "bundle_info.plist" ]
+then
+ echo -e $ABORT "bundle_info.plist does not exist."
+ exit 1
+fi
+
+BUNDLE_PATH=$BUNDLE_NAME.app
+BIN_DIR=$BUNDLE_PATH/Contents/MacOS
+DYNLIB_DIR=$BUNDLE_PATH/Contents/lib
+FRAMEWORK_DIR=$BUNDLE_PATH/Contents/Frameworks
+RES_DIR=$BUNDLE_PATH/Contents/Resources
+APP_PATH=$BIN_DIR/$APP_NAME
+
+if [ -d "$BUNDLE_PATH" ]
+then
+ echo -e $INFO "Removing old bundle."
+ rm -rf $BUNDLE_PATH
+fi
+
+echo -e $INFO "Creating bundle folders."
+mkdir -p $BIN_DIR
+mkdir -p $DYNLIB_DIR
+mkdir -p $FRAMEWORK_DIR
+mkdir -p $RES_DIR
+
+echo -e $INFO "Copying bundle contents."
+cp $APP_NAME $APP_PATH
+cp bundle_info.plist $BUNDLE_PATH/Contents/Info.plist
+cp -R ../data $RES_DIR/data
+
+echo -e $INFO "Copying dynamic libraries."
+for LIB_PATH in ${DYNLIB_PATHS[@]}
+do
+ LIB_NAME=$(basename $LIB_PATH)
+ cp $LIB_PATH $DYNLIB_DIR/$LIB_NAME
+ install_name_tool -change $LIB_NAME @executable_path/../lib/$LIB_NAME $APP_PATH
+
+ echo $LIB_PATH $LIB_NAME
+done
+
+echo -e $INFO "Copying frameworks."
+for FRAMEWORK_BIN_PATH in ${FRAMEWORK_PATHS[@]}
+do
+ FRAMEWORK_PATH=$(echo $FRAMEWORK_BIN_PATH | grep -o "\S*.framework")
+ FRAMEWORK_NAME=$(echo $FRAMEWORK_BIN_PATH | grep -o "\w*.framework")
+ cp -R $FRAMEWORK_PATH $FRAMEWORK_DIR/$FRAMEWORK_NAME
+
+ FRAMEWORK_SUB_PATH=$(echo $FRAMEWORK_BIN_PATH | grep -o "\w*.framework\S*")
+ install_name_tool -change $FRAMEWORK_BIN_PATH @loader_path/../Frameworks/$FRAMEWORK_SUB_PATH $APP_PATH
+
+ echo $FRAMEWORK_BIN_PATH $FRAMEWORK_PATH
+done
+
+otool -L $APP_PATH
+
+echo -e $SUCCESS "Installed bundle successfully!"
diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
index 872ec856..d38f4f22 100644
--- a/src/app/CMakeLists.txt
+++ b/src/app/CMakeLists.txt
@@ -1,6 +1,10 @@
add_files(
APP_FILES
+ platform_includes/includesDefault.h
+ platform_includes/includesMac.h
+ platform_includes/includesWindows.h
+
qt/element/QtCodeFile.cpp
qt/element/QtCodeFile.h
qt/element/QtButton.cpp
@@ -39,6 +43,5 @@ add_files(
qt/QtWidgetWrapper.cpp
qt/QtWidgetWrapper.h
- includesWindows.h
main.cpp
)
diff --git a/src/app/includes.h.in b/src/app/includes.h.in
deleted file mode 100644
index 5ccc1844..00000000
--- a/src/app/includes.h.in
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef INCLUDES_H
-#define INCLUDES_H
-
-// platform specific includes
-@PLATFORM_INCLUDES@
-
-#endif // INCLUDES_H
diff --git a/src/app/main.cpp b/src/app/main.cpp
index bbca8dc7..bf5859fd 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -3,12 +3,14 @@
#include
#include "Application.h"
-#include "includes.h"
+#include "includes.h" // defines 'void setup()'
#include "qt/QtGuiFactory.h"
#include "qt/utility/utilityQt.h"
int main(int argc, char *argv[])
{
+ setup();
+
QApplication qtApp(argc, argv);
QtGuiFactory guiFactory;
diff --git a/src/app/platform_includes/includes.h.in b/src/app/platform_includes/includes.h.in
new file mode 100644
index 00000000..24636dce
--- /dev/null
+++ b/src/app/platform_includes/includes.h.in
@@ -0,0 +1,9 @@
+#ifndef INCLUDES_H
+#define INCLUDES_H
+
+void setup();
+
+// platform specific include
+#include "platform_includes/@PLATFORM_INCLUDE@"
+
+#endif // INCLUDES_H
diff --git a/src/app/platform_includes/includesDefault.h b/src/app/platform_includes/includesDefault.h
new file mode 100644
index 00000000..88535638
--- /dev/null
+++ b/src/app/platform_includes/includesDefault.h
@@ -0,0 +1,8 @@
+#ifndef INCLUDES_DEFAULT_H
+#define INCLUDES_DEFAULT_H
+
+void setup()
+{
+}
+
+#endif // INCLUDES_DEFAULT_H
\ No newline at end of file
diff --git a/src/app/platform_includes/includesMac.h b/src/app/platform_includes/includesMac.h
new file mode 100644
index 00000000..ffaa0e31
--- /dev/null
+++ b/src/app/platform_includes/includesMac.h
@@ -0,0 +1,34 @@
+#ifndef INCLUDES_MAC_H
+#define INCLUDES_MAC_H
+
+#include
+
+void setup()
+{
+ // ----------------------------------------------------------------------------
+ // This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
+ // source: http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c
+ CFBundleRef mainBundle = CFBundleGetMainBundle();
+ if (!mainBundle)
+ {
+ return;
+ }
+
+ CFStringRef bundleIdentifier = CFBundleGetIdentifier(mainBundle);
+ // std::cout << CFStringGetCStringPtr(id, kCFStringEncodingASCII) << std::endl;
+ if (!bundleIdentifier)
+ {
+ return;
+ }
+
+ CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
+ char path[PATH_MAX];
+ if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
+ {
+ chdir(path);
+ }
+ CFRelease(resourcesURL);
+ // ----------------------------------------------------------------------------
+}
+
+#endif // INCLUDES_MAC_H
diff --git a/src/app/includesWindows.h b/src/app/platform_includes/includesWindows.h
similarity index 85%
rename from src/app/includesWindows.h
rename to src/app/platform_includes/includesWindows.h
index 0f6f0018..302fcc5c 100644
--- a/src/app/includesWindows.h
+++ b/src/app/platform_includes/includesWindows.h
@@ -3,4 +3,8 @@
#include "vld.h"
+void setup()
+{
+}
+
#endif // INCLUDES_WINDOWS_H