Commit 52ddfbf2 authored by Stéphane Albert's avatar Stéphane Albert

ENH: Loading translation files from build and install directory only if...

ENH: Loading translation files from build and install directory only if translation is needed. (ref. MVDX-9, MVDX-11).
parent 428664a7
#
# This function will prevent in-source builds
function(AssureOutOfSourceBuilds)
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.6)
# make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
else()
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" ABSOLUTE)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" ABSOLUTE)
endif()
# disallow in-source builds
if("${srcdir}" STREQUAL "${bindir}")
message("######################################################")
message("# OTB should not be configured & built in the OTB source directory")
message("# You must run cmake in a build directory.")
message("# For example:")
message("# mkdir OTB-Sandbox ; cd OTB-Sandbox")
message("# hg clone http://hg.orfeo-toolbox.org/OTB # or download & unpack the source tarball")
message("# mkdir OTB-Binary ")
message("# this will create the following directory structure ")
message("# ")
message("# OTB-Sandbox")
message("# +--OTB ")
message("# +--OTB-Binary ")
message("# ")
message("# Then you can proceed to configure and build ")
message("# by using the following commands ")
message("# ")
message("# cd OTB-Binary")
message("# ccmake ../OTB")
message("# make ")
message("# ")
message("# NOTE: Given that you already tried to make an in-source build")
message("# CMake have already created several files & directories")
message("# in your source tree. run 'hg status' to find them and")
message("# remove them by doing:")
message("# ")
message("# cd OTB-Sandbox/OTB")
message("# hg purge ")
message("# ")
message("######################################################")
message(FATAL_ERROR "Quitting configuration")
endif()
endfunction()
AssureOutOfSourceBuilds()
# Make sure the user does not try to install on top of the build tree.
IF(WIN32 OR APPLE OR UNIX)
STRING(TOLOWER "${CMAKE_INSTALL_PREFIX}" _PREFIX)
STRING(TOLOWER "${OTB_BINARY_DIR}" _BUILD)
ELSE(WIN32 OR APPLE OR UNIX)
SET(_PREFIX "${CMAKE_INSTALL_PREFIX}")
SET(_BUILD "${OTB_BINARY_DIR}")
ENDIF(WIN32 OR APPLE OR UNIX)
IF("${_PREFIX}" STREQUAL "${_BUILD}")
MESSAGE(FATAL_ERROR
"The current CMAKE_INSTALL_PREFIX points at the build tree:\n"
" ${CMAKE_INSTALL_PREFIX}\n"
"This is not supported."
)
ENDIF("${_PREFIX}" STREQUAL "${_BUILD}")
......@@ -79,11 +79,6 @@ if(Mercurial_FOUND)
mark_as_advanced(Monteverdi2_WC_STATUS)
endif(Mercurial_FOUND)
#----------------------------------------------------------------------------
# Configure files with settings for use by the build.
configure_file(${Monteverdi2_SOURCE_DIR}/ConfigureMonteverdi2.h.in
${Monteverdi2_BINARY_DIR}/ConfigureMonteverdi2.h)
#----------------------------------------------------------------------------
#Build shared libraries for monteverdi
#By default, import the option from the OTB configuration
......@@ -120,16 +115,12 @@ set(Monteverdi2_INCLUDE_DIRS
include_directories(${Monteverdi2_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
#----------------------------------------------------------------------------
# Installation vars:
#
# Installation directories:
# Monteverdi2_INSTALL_BIN_DIR - binary dir (executables)
# Monteverdi2_INSTALL_LIB_DIR - library dir (libs)
# Monteverdi2_INSTALL_DATA_DIR - share dir (say, examples, data, etc)
# Monteverdi2_INSTALL_INCLUDE_DIR - include dir (headers)
# Monteverdi2_INSTALL_PACKAGE_DIR - package/export configuration files
# Monteverdi2_INSTALL_NO_DEVELOPMENT - do not install development files
# Monteverdi2_INSTALL_NO_RUNTIME - do not install runtime files
# Monteverdi2_INSTALL_NO_DOCUMENTATION - do not install documentation files
if(NOT Monteverdi2_INSTALL_BIN_DIR)
set(Monteverdi2_INSTALL_BIN_DIR "bin")
......@@ -152,26 +143,16 @@ if(NOT Monteverdi2_INSTALL_PACKAGE_DIR)
endif(NOT Monteverdi2_INSTALL_PACKAGE_DIR)
#----------------------------------------------------------------------------
# Make sure the user does not try to install on top of the build tree.
if(WIN32 OR APPLE OR UNIX)
string(TOLOWER "${CMAKE_INSTALL_PREFIX}" _PREFIX)
string(TOLOWER "${Monteverdi2_BINARY_DIR}" _BUILD)
else(WIN32 OR APPLE OR UNIX)
set(_PREFIX "${CMAKE_INSTALL_PREFIX}")
set(_BUILD "${Monteverdi2_BINARY_DIR}")
endif(WIN32 OR APPLE OR UNIX)
if("${_PREFIX}" STREQUAL "${_BUILD}")
message(FATAL_ERROR
"The current CMAKE_INSTALL_PREFIX points at the build tree:\n"
" ${CMAKE_INSTALL_PREFIX}\n"
"This is not supported."
)
endif("${_PREFIX}" STREQUAL "${_BUILD}")
include( PreventInSourceBuilds )
include( PreventInstallOnBuildTree )
#----------------------------------------------------------------------------
# Code location
add_subdirectory( Code )
add_subdirectory( i18n )
# Configure files with settings for use by the build.
set( Monteverdi2_CONFIGURE_FILE "ConfigureMonteverdi2.h" )
configure_file(
${Monteverdi2_SOURCE_DIR}/${Monteverdi2_CONFIGURE_FILE}.in
${Monteverdi2_BINARY_DIR}/${Monteverdi2_CONFIGURE_FILE}
)
#----------------------------------------------------------------------------
# Include the Packaging subdir after every other dir
......@@ -179,12 +160,17 @@ add_subdirectory( i18n )
#add_subdirectory(Packaging)
#-----------------------------------------------------------------------------
# Output directories.
set(LIBRARY_OUTPUT_PATH ${Monteverdi2_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
set(EXECUTABLE_OUTPUT_PATH ${Monteverdi2_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all executables.")
mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
#set(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
# Output (build) directories.
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Monteverdi2_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Monteverdi2_BINARY_DIR}/lib )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Monteverdi2_BINARY_DIR}/lib )
#----------------------------------------------------------------------------
# Code location
add_subdirectory( Code )
add_subdirectory( i18n )
#----------------------------------------------------------------------------
# Enable / Disable testing
#option(BUILD_TESTING "Build testing." OFF)
......@@ -200,20 +186,18 @@ mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
#----------------------------------------------------------------------------
# Generate Monteverdi2Config.cmake
# Save library dependencies.
set(Monteverdi2_LIBRARY_DEPENDS_FILE ${Monteverdi2_BINARY_DIR}/Monteverdi2LibraryDepends.cmake)
export_library_dependencies(${Monteverdi2_LIBRARY_DEPENDS_FILE})
# Library directory.
set(Monteverdi2_LIBRARY_DIRS ${OTB_LIBRARY_DIRS} ${LIBRARY_OUTPUT_PATH})
# set(Monteverdi2_LIBRARY_DEPENDS_FILE ${Monteverdi2_BINARY_DIR}/Monteverdi2LibraryDepends.cmake)
# export_library_dependencies(${Monteverdi2_LIBRARY_DEPENDS_FILE})
#set(Monteverdi2_USE_FILE ${Monteverdi2_BINARY_DIR}/UseMonteverdi2.cmake)
#configure_file(${Monteverdi2_SOURCE_DIR}/Monteverdi2Config.cmake.in
# ${Monteverdi2_BINARY_DIR}/Monteverdi2Config.cmake @ONLY IMMEDIATE)
#configure_file(${Monteverdi2_SOURCE_DIR}/UseMonteverdi2.cmake.in
# ${Monteverdi2_USE_FILE} @ONLY IMMEDIATE)
# # Library directory.
# set(Monteverdi2_LIBRARY_DIRS ${OTB_LIBRARY_DIRS} ${LIBRARY_OUTPUT_PATH})
# set(Monteverdi2_USE_FILE ${Monteverdi2_BINARY_DIR}/UseMonteverdi2.cmake)
# configure_file(${Monteverdi2_SOURCE_DIR}/Monteverdi2Config.cmake.in
# ${Monteverdi2_BINARY_DIR}/Monteverdi2Config.cmake @ONLY IMMEDIATE)
# configure_file(${Monteverdi2_SOURCE_DIR}/UseMonteverdi2.cmake.in
# ${Monteverdi2_USE_FILE} @ONLY IMMEDIATE)
#----------------------------------------------------------------------------
# Setup valgrind option (default hard coded value is ctest is invalid).
#set(VALGRIND_COMMAND_OPTIONS "--show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=50")
# set(VALGRIND_COMMAND_OPTIONS "--show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=50")
......@@ -39,6 +39,7 @@
//
// Class pre-declaration.
//
// Class implementation.
namespace mvd
......@@ -79,12 +80,17 @@ Application::Initialize()
void
Application::InitializeCore()
{
//
// Setup application tags.
QCoreApplication::setApplicationName(
PROJECT_NAME
);
QCoreApplication::setApplicationVersion(
Monteverdi2_VERSION_STRING
);
//
// Setup organization tags.
QCoreApplication::setOrganizationName(
"Centre National d'Etudes Spatiales (CNES)"
);
......@@ -93,16 +99,24 @@ Application::InitializeCore()
);
}
/*******************************************************************************/
void
Application::InitializeDataDir()
{
}
/*******************************************************************************/
void
Application::InitializeLocale()
{
/*
qDebug() << "UI languages: " << QLocale::system().uiLanguages();
qDebug() << "System: " << QLocale::system();
qDebug() << "en_US: " << QLocale( QLocale::English, QLocale::UnitedStates );
*/
//
// default UI language is en-US (no translation).
// 1. default UI language is en-US (no translation).
QLocale sys_lc( QLocale::system() );
QLocale en_US_lc( QLocale::English, QLocale::UnitedStates );
if( sys_lc.language()==en_US_lc.language() &&
......@@ -113,49 +127,67 @@ Application::InitializeLocale()
}
//
// Desired locale name.
QString lc_name( QLocale::system().name() );
//
// Choose i18n path between build dir and install dir.
// 2. Choose i18n path between build dir and install dir.
QDir i18n_dir;
QDir build_dir( QDir::cleanPath( QCoreApplication::applicationDirPath() ) );
qDebug() << "Build dir: " << build_dir;
QDir i18n_build_dir( QDir::cleanPath( build_dir.path() + "/../i18n" ) );
qDebug() << "I18N build dir: " << i18n_build_dir;
QDir install_dir( QDir::cleanPath( Monteverdi2_INSTALL_DATA_DIR ) );
qDebug() << "Install dir: " << install_dir;
QDir i18n_install_dir( QDir::cleanPath( install_dir.path() + "/../i18n" ) );
qDebug() << "I18N install dir: " << i18n_install_dir;
QDir bin_dir( QDir::cleanPath( QCoreApplication::applicationDirPath() ) );
qDebug() << "Binary dir: " << bin_dir;
QDir build_i18n_dir( bin_dir );
// If build dir is identified...
if( i18n_build_dir.exists() &&
i18n_build_dir.exists( "../ConfigureMonteverdi2.h" ) )
if( build_i18n_dir.cd( "../i18n" ) &&
build_i18n_dir.exists( "../" Monteverdi2_CONFIGURE_FILE ) )
{
// ...use build dir as prioritary load path.
i18n_dir = i18n_build_dir;
qDebug() << "Build I18N dir: " << build_i18n_dir;
// ...use build dir as prioritary load path for translation.
i18n_dir = build_i18n_dir;
// TODO: Use log system to trace message.
qDebug()
<< tr( "Running from build directory '%1'" ).arg( build_dir.path() );
<< tr( "Running from build directory '%1'" ).arg( bin_dir.path() );
}
// Otherwise...
else
{
// ...use install dir if application is installed in the system.
i18n_dir = i18n_install_dir;
// TODO: Use log system to trace message.
qDebug()
<< tr( "Running from install directory '%1'" ).arg( install_dir.path() );
QDir install_i18n_dir( QDir::cleanPath( Monteverdi2_INSTALL_DATA_I18N_DIR ) );
qDebug() << "Install data dir: " << install_i18n_dir;
// ...if install data dir is identified
if( install_i18n_dir.exists() )
{
// ...use install data dir as load path for translation.
i18n_dir = install_i18n_dir;
// TODO: Use log system to trace message.
qDebug()
<< tr( "Running from install directory '%1'" ).arg( install_i18n_dir.path() );
}
// Otherwise
else
{
QString message(
tr( "Failed to access translation-files directory '%1'." )
.arg( install_i18n_dir.path() )
);
// TODO: Use log system to trace error while loading locale translation file.
qDebug() << message;
// TODO: morph into better HMI design.
QMessageBox::critical( NULL, "Critical...", message );
return;
}
}
//
// Load QTranslator.
// 3. Desired locale name.
QString lc_name( QLocale::system().name() );
//
// 4. Load QTranslator.
QString lc_filename( i18n_dir.filePath( lc_name ) );
qDebug() << "Filename: " << lc_name;
// (a) No need to new QTranslator() here nor delete in destructor...
......
......@@ -75,6 +75,10 @@ private:
*/
void InitializeCore();
/**
*/
void InitializeDataDir();
/**
*/
void InitializeLocale();
......
//
// Qt includes
// System includes (sorted by alphabetic order).
#include <cassert>
//
// Qt includes (sorted by alphabetic order).
#include <QDebug> // temporary (experimental version).
//
......@@ -15,9 +19,18 @@
//
// Directories
#define Monteverdi2_INSTALL_INCLUDE_DIR "@Monteverdi2_INSTALL_INCLUDE_DIR@"
#define Monteverdi2_INSTALL_LIB_DIR "@Monteverdi2_INSTALL_LIB_DIR@"
#define Monteverdi2_INSTALL_DATA_DIR "@Monteverdi2_INSTALL_DATA_DIR@"
#define Monteverdi2_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
#define Monteverdi2_INSTALL_BIN_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_BIN_DIR@"
#define Monteverdi2_INSTALL_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_INCLUDE_DIR@"
#define Monteverdi2_INSTALL_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_LIB_DIR@"
#define Monteverdi2_INSTALL_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_DATA_DIR@"
//
// Sub-directories
#define Monteverdi2_INSTALL_DATA_I18N_DIR Monteverdi2_INSTALL_DATA_DIR "/i18n"
//
// Files
#define Monteverdi2_CONFIGURE_FILE "@Monteverdi2_CONFIGURE_FILE@"
//
// Miscellaneous
......
......@@ -30,5 +30,5 @@ add_custom_target( i18n ALL DEPENDS ${Monteverdi2_QM_TRANSLATIONS} )
#----------------------------------------------------------------------------
# Locale human-readable translation files.
install(
FILES ${Monteverdi2_QM_TRANSLATIONS} DESTINATION ${Monteverdi2_INSTALL_DATA_DIR}
FILES ${Monteverdi2_QM_TRANSLATIONS} DESTINATION ${Monteverdi2_INSTALL_DATA_DIR}/i18n
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment