diff --git a/CMakeLists.txt b/CMakeLists.txt index ea2b1147e..001bf784f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,61 +62,74 @@ option (WITH_RAWZOR "Build with Rawzor support" OFF) option (WITH_BZIP "Build with Bzip2 support" ON) option (WITH_MYFILE_MMAP "Build using memory mapped file" ON) option (OPTION_OMP "Build with OpenMP support" ON) +option (BUILD_BUNDLE "Self-contained build" OFF) # set install directories -if (NOT DEFINED DATADIR) - if (WIN32 OR APPLE) - set (DATADIR ${CMAKE_CURRENT_SOURCE_DIR}/release) - else (WIN32 OR APPLE) - set (DATADIR ${CMAKE_INSTALL_PREFIX}/share/rawtherapee) - endif (WIN32 OR APPLE) -endif (NOT DEFINED DATADIR) +if (WIN32 OR APPLE) + set (BUILD_BUNDLE ON FORCE) +endif(WIN32 OR APPLE) + +if (BUILD_BUNDLE) + set (BINDIR .) + set (CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_BUILD_TYPE}) +endif (BUILD_BUNDLE) if (NOT DEFINED BINDIR) - if (WIN32 OR APPLE) - set (BINDIR ${CMAKE_CURRENT_SOURCE_DIR}/release) - else (WIN32 OR APPLE) - set (BINDIR ${CMAKE_INSTALL_PREFIX}/bin) - endif (WIN32 OR APPLE) + set (BINDIR ${CMAKE_INSTALL_PREFIX}/bin) endif (NOT DEFINED BINDIR) +if (NOT DEFINED DATADIR) + if (BUILD_BUNDLE) + set (DATADIR .) + else (BUILD_BUNDLE) + set (DATADIR ${CMAKE_INSTALL_PREFIX}/share/rawtherapee) + endif (BUILD_BUNDLE) +endif (NOT DEFINED DATADIR) + if (NOT DEFINED LIBDIR) - if (WIN32 OR APPLE) - set (LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/release) - else (WIN32 OR APPLE) + if (BUILD_BUNDLE) + set (LIBDIR .) + else (BUILD_BUNDLE) # Respect CMAKE_INSTALL_LIBDIR if set if (DEFINED CMAKE_INSTALL_LIBDIR) set (LIBDIR ${CMAKE_INSTALL_LIBDIR}) else (DEFINED CMAKE_INSTALL_LIBDIR) set (LIBDIR ${CMAKE_INSTALL_PREFIX}/lib) endif (DEFINED CMAKE_INSTALL_LIBDIR) - endif (WIN32 OR APPLE) + endif (BUILD_BUNDLE) endif (NOT DEFINED LIBDIR) if (NOT DEFINED DOCDIR) - if (WIN32 OR APPLE) - set (DOCDIR ${CMAKE_CURRENT_SOURCE_DIR}/release/doc) - else (WIN32 OR APPLE) - set (DOCDIR ${CMAKE_INSTALL_PREFIX}/share/doc) - endif (WIN32 OR APPLE) + if (BUILD_BUNDLE) + set (DOCDIR ./doc) + else (BUILD_BUNDLE) + set (DOCDIR ${CMAKE_INSTALL_PREFIX}/share/doc/rawtherapee) + endif (BUILD_BUNDLE) endif (NOT DEFINED DOCDIR) if (NOT DEFINED CREDITSDIR) - if (WIN32 OR APPLE) - set (CREDITSDIR ${CMAKE_CURRENT_SOURCE_DIR}/release) - else (WIN32 OR APPLE) - set (CREDITSDIR ${CMAKE_INSTALL_PREFIX}/share/doc) - endif (WIN32 OR APPLE) + if (BUILD_BUNDLE) + set (CREDITSDIR .) + else (BUILD_BUNDLE) + set (CREDITSDIR ${CMAKE_INSTALL_PREFIX}/share/doc/rawtherapee) + endif (BUILD_BUNDLE) endif (NOT DEFINED CREDITSDIR) if (NOT DEFINED LICENCEDIR) - if (WIN32 OR APPLE) - set (LICENCEDIR ${CMAKE_CURRENT_SOURCE_DIR}/release) - else (WIN32 OR APPLE) - set (LICENCEDIR ${CMAKE_INSTALL_PREFIX}/share/doc) - endif (WIN32 OR APPLE) + if (BUILD_BUNDLE) + set (LICENCEDIR .) + else (BUILD_BUNDLE) + set (LICENCEDIR ${CMAKE_INSTALL_PREFIX}/share/doc/rawtherapee) + endif (BUILD_BUNDLE) endif (NOT DEFINED LICENCEDIR) +# non-bundle builds has to use absolute paths +if (NOT BUILD_BUNDLE AND + NOT (IS_ABSOLUTE ${BINDIR} AND IS_ABSOLUTE ${DATADIR} AND IS_ABSOLUTE ${LIBDIR} AND + IS_ABSOLUTE ${DOCDIR} AND IS_ABSOLUTE ${CREDITSDIR} AND IS_ABSOLUTE ${LICENCEDIR})) + message (FATAL_ERROR "The paths has to be absolute or use -DBUILD_BUNDLE=ON") +endif () + # check for libraries find_package(PkgConfig) pkg_check_modules (GTK REQUIRED gtk+-2.0>=2.12) @@ -314,10 +327,6 @@ if (OPTION_OMP) endif (OPENMP_FOUND) endif (OPTION_OMP) -if (UNIX) - install (PROGRAMS rtstart DESTINATION ${BINDIR}) -endif (UNIX) - install (FILES AUTHORS.txt DESTINATION ${CREDITSDIR}) install (FILES LICENSE.txt DESTINATION ${LICENCEDIR}) install (FILES AboutThisBuild.txt DESTINATION ${CREDITSDIR}) diff --git a/rtgui/CMakeLists.txt b/rtgui/CMakeLists.txt index ed28a6717..868ee85ec 100644 --- a/rtgui/CMakeLists.txt +++ b/rtgui/CMakeLists.txt @@ -44,9 +44,9 @@ else (WIN32) ${GTK_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS} ${GIOMM_INCLUDE_DIRS} ${IPTCDATA_INCLUDE_DIRS} ${LCMS_INCLUDE_DIRS} ${GTHREAD_INCLUDE_DIRS} ${GOBJECT_INCLUDE_DIRS} ) link_directories (${EXTRA_LIBDIR} ${GLIB2_LIBRARY_DIRS} ${GLIBMM_LIBRARY_DIRS} ${GTK_LIBRARY_DIRS} ${GTKMM_LIBRARY_DIRS} ${GIO_LIBRARY_DIRS} ${GIOMM_LIBRARY_DIRS} ${IPTCDATA_LIBRARY_DIRS} ${LCMS_LIBRARY_DIRS} ${GTHREAD_LIBRARY_DIRS} ${GOBJECT_LIBRARY_DIRS}) - # create config.h which defines where data are stored - configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) endif (WIN32) +# create config.h which defines where data are stored +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) add_executable (rth ${EXTRA_SRC} ${BASESOURCEFILES}) diff --git a/rtgui/config.h.in b/rtgui/config.h.in index d5f46316c..cab481278 100644 --- a/rtgui/config.h.in +++ b/rtgui/config.h.in @@ -20,6 +20,7 @@ #ifndef __CONFIG_H__ #define __CONFIG_H__ +#cmakedefine BUILD_BUNDLE #define DATA_SEARCH_PATH "${DATADIR}" #define DOC_SEARCH_PATH "${DOCDIR}" #define CREDITS_SEARCH_PATH "${CREDITSDIR}" diff --git a/rtgui/main.cc b/rtgui/main.cc index 63bacf7e0..7630d97c2 100644 --- a/rtgui/main.cc +++ b/rtgui/main.cc @@ -23,7 +23,7 @@ // This file is for your program, I won't touch it again! -//#include +#include #include #include #include @@ -35,7 +35,6 @@ #include "version.h" #ifndef WIN32 -#include #include #include #include @@ -47,6 +46,8 @@ extern Options options; // stores path to data files Glib::ustring argv0; +Glib::ustring creditsPath; +Glib::ustring licensePath; Glib::ustring argv1; bool simpleEditor; @@ -60,34 +61,43 @@ bool simpleEditor; int processLineParams( int argc, char **argv ); int main(int argc, char **argv) -{ - - Glib::ustring argv0_; - -#ifdef WIN32 - - WCHAR exnameU[512] = {0}; - char exname[512] = {0}; - GetModuleFileNameW (NULL, exnameU, 512); - WideCharToMultiByte(CP_UTF8,0,exnameU,-1,exname,512,0,0 ); - argv0_ = exname; - - // get the path where the rawtherapee executable is stored - argv0 = Glib::path_get_dirname(argv0_); +{ +#ifdef BUILD_BUNDLE + char exname[512] = {0}; + Glib::ustring exePath; + // get the path where the rawtherapee executable is stored + #ifdef WIN32 + WCHAR exnameU[512] = {0}; + GetModuleFileNameW (NULL, exnameU, 512); + WideCharToMultiByte(CP_UTF8,0,exnameU,-1,exname,512,0,0 ); + #else + if (readlink("/proc/self/exe", exname, 512) < 0) { + strncpy(exname, argv[0], 512); + } + #endif + exePath = Glib::path_get_dirname(exname); + // set paths + if (Glib::path_is_absolute(DATA_SEARCH_PATH)) { + argv0 = DATA_SEARCH_PATH; + } else { + argv0 = Glib::build_filename(exePath, DATA_SEARCH_PATH); + } + if (Glib::path_is_absolute(CREDITS_SEARCH_PATH)) { + creditsPath = CREDITS_SEARCH_PATH; + } else { + creditsPath = Glib::build_filename(exePath, CREDITS_SEARCH_PATH); + } + if (Glib::path_is_absolute(LICENCE_SEARCH_PATH)) { + licensePath = LICENCE_SEARCH_PATH; + } else { + licensePath = Glib::build_filename(exePath, LICENCE_SEARCH_PATH); + } #else - // get the path to data (defined in config.h which is generated by cmake) - argv0 = DATA_SEARCH_PATH; - // check if path exists, otherwise revert back to behavior similar to windows - try { - Glib::Dir dir(DATA_SEARCH_PATH); - } catch (Glib::FileError) { - argv0_ = argv[0]; - argv0 = Glib::path_get_dirname(argv0_); - } + argv0 = DATA_SEARCH_PATH; + creditsPath = CREDITS_SEARCH_PATH; + licensePath = LICENCE_SEARCH_PATH; #endif - - Glib::thread_init(); gdk_threads_init(); @@ -127,16 +137,16 @@ int main(int argc, char **argv) } Gtk::Main m(&argc, &argv); -#ifndef WIN32 - // For an unknown reason, gtkmm 2.22 don't know the gtk-button-images property, while it exists in the documentation... - // Anyway, the problem was Linux only - static Glib::RefPtr settings = Gtk::Settings::get_default(); - if (settings) - settings->property_gtk_button_images().set_value(true); - else - printf("Error: no default settings to update!\n"); -#endif - +#ifndef WIN32 + // For an unknown reason, gtkmm 2.22 don't know the gtk-button-images property, while it exists in the documentation... + // Anyway, the problem was Linux only + static Glib::RefPtr settings = Gtk::Settings::get_default(); + if (settings) + settings->property_gtk_button_images().set_value(true); + else + printf("Error: no default settings to update!\n"); +#endif + RTWindow *rtWindow = new class RTWindow(); gdk_threads_enter (); m.run(*rtWindow); @@ -146,7 +156,6 @@ int main(int argc, char **argv) return 0; } - int processLineParams( int argc, char **argv ) { std::vector inputFiles; diff --git a/rtgui/splash.cc b/rtgui/splash.cc index 6ced387b7..f3b8300e3 100644 --- a/rtgui/splash.cc +++ b/rtgui/splash.cc @@ -21,11 +21,9 @@ #include #include -#ifndef WIN32 -#include -#endif - extern Glib::ustring argv0; +extern Glib::ustring creditsPath; +extern Glib::ustring licensePath; extern Glib::ustring versionString; SplashImage::SplashImage () { @@ -86,11 +84,7 @@ Splash::Splash () { splashImage->show (); // Tab 2: the informations about the current version -#if defined WIN32 || defined __APPLE__ - std::string buildFileName = Glib::build_filename (argv0, "AboutThisBuild.txt"); -#else - std::string buildFileName = Glib::build_filename (CREDITS_SEARCH_PATH, "AboutThisBuild.txt"); -#endif + std::string buildFileName = Glib::build_filename (creditsPath, "AboutThisBuild.txt"); if ( safe_file_test(buildFileName, (Glib::FILE_TEST_EXISTS)) ) { FILE *f = safe_g_fopen (buildFileName, "rt"); if (f != NULL) { @@ -113,11 +107,7 @@ Splash::Splash () { } // Tab 3: the credits -#if defined WIN32 || defined __APPLE__ - std::string creditsFileName = Glib::build_filename (argv0, "AUTHORS.txt"); -#else - std::string creditsFileName = Glib::build_filename (CREDITS_SEARCH_PATH, "AUTHORS.txt"); -#endif + std::string creditsFileName = Glib::build_filename (creditsPath, "AUTHORS.txt"); if ( safe_file_test(creditsFileName, (Glib::FILE_TEST_EXISTS)) ) { FILE *f = safe_g_fopen (creditsFileName, "rt"); if (f != NULL) { @@ -140,11 +130,7 @@ Splash::Splash () { } // Tab 4: the license -#if defined WIN32 || defined __APPLE__ - std::string licenseFileName = Glib::build_filename (argv0, "LICENSE.txt"); -#else - std::string licenseFileName = Glib::build_filename (LICENCE_SEARCH_PATH, "LICENSE.txt"); -#endif + std::string licenseFileName = Glib::build_filename (licensePath, "LICENSE.txt"); if ( safe_file_test(licenseFileName, (Glib::FILE_TEST_EXISTS)) ) { FILE *f = safe_g_fopen (licenseFileName, "rt"); if (f != NULL) { diff --git a/rtstart b/rtstart deleted file mode 100755 index 2f9c77d59..000000000 --- a/rtstart +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -RT_BINDIR=`dirname "$0"` -export LD_LIBRARY_PATH=${RT_BINDIR} -cd "${RT_BINDIR}" && ./rawtherapee "$@"