Skip to content

Commit

Permalink
Close INPE-EM#22 - Build on mac.
Browse files Browse the repository at this point in the history
  • Loading branch information
avancinirodrigo committed Dec 2, 2020
1 parent 1bd3c1e commit 03850c5
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 24 deletions.
3 changes: 3 additions & 0 deletions build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ endif()
# endif()

#add_subdirectory(cppcli)

include(inpeem_macros.cmake)

add_subdirectory(qt)

configure_file(${PROJECT_SOURCE_DIR}/cpack_installer_generator.cmake.in
Expand Down
69 changes: 66 additions & 3 deletions build/cmake/fixup_bundle.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,70 @@
include(BundleUtilities)

set(INPEEM_APP_PATH ${CMAKE_INSTALL_PREFIX}/@PROJECT_NAME@.exe)
file(GLOB INPEEM_LIBS ${CMAKE_INSTALL_PREFIX}/*@CMAKE_SHARED_LIBRARY_SUFFIX@)
set(INPEEM_PATHS ${CMAKE_INSTALL_PREFIX};@Qt5_DIR@/../../../bin)
if(WIN32)
set(INPEEM_APP_PATH ${CMAKE_INSTALL_PREFIX}/@PROJECT_NAME@.exe)
file(GLOB INPEEM_LIBS ${CMAKE_INSTALL_PREFIX}/*@CMAKE_SHARED_LIBRARY_SUFFIX@)
set(INPEEM_PATHS ${CMAKE_INSTALL_PREFIX};@Qt5_DIR@/../../../bin)
elseif(APPLE)
set(BU_CHMOD_BUNDLE_ITEMS ON)
set(INPEEM_APP_PATH ${CMAKE_INSTALL_PREFIX}/@PROJECT_NAME@.app)
set(INPEEM_QT_PLUGINS_ABSOLUTE_LOCATION ${CMAKE_INSTALL_PREFIX}/@INPEEM_QT_PLUGINS_LOCATION@)
file(GLOB_RECURSE QT_PLUGINS "${INPEEM_QT_PLUGINS_ABSOLUTE_LOCATION}/*@CMAKE_SHARED_LIBRARY_SUFFIX@")
set(INPEEM_LIBS ${INPEEM_LIBS} ${QT_PLUGINS})
#message("${QT_PLUGINS}---------------------${INPEEM_QT_PLUGINS_ABSOLUTE_LOCATION}")
#exit()
set(INPEEM_PATHS ${CMAKE_INSTALL_PREFIX};@Qt5_DIR@/../..)
endif()

if(APPLE)
# Overload function
function(gp_item_default_embedded_path item default_embedded_path_var)
set(is_System FALSE)
set(is_QImageFormat FALSE)
set(is_QIconEngine FALSE)
set(is_QSQLDrivers FALSE)
set(is_QPlatforms FALSE)
set(is_Lib FALSE)

get_filename_component (resolved_file ${item} PATH)

if("${resolved_file}" STREQUAL "")
set (is_Lib TRUE)
elseif(resolved_file MATCHES "^(@rpath)")
set(is_Lib TRUE)
elseif(resolved_file MATCHES "^(/System/Library/|/usr/lib|/usr/local|@loader_path)")
set(is_System TRUE)
elseif(resolved_file MATCHES "(imageformats)$")
set (is_QImageFormat TRUE)
elseif(resolved_file MATCHES "(iconengines)$")
set (is_QIconEngine TRUE)
elseif(resolved_file MATCHES "(sqldrivers)$")
set (is_QSQLDrivers TRUE)
elseif(resolved_file MATCHES "(platforms)$")
set (is_QPlatforms TRUE)
elseif(resolved_file MATCHES "(lib)$")
set (is_Lib TRUE)
endif()

if(item MATCHES "\\.dylib$")
if(is_System)
set(${default_embedded_path_var} "@executable_path/../lib" PARENT_SCOPE)
elseif(is_QImageFormat)
set(${default_embedded_path_var} "@executable_path/../qtplugins/imageformats" PARENT_SCOPE)
elseif(is_QIconEngine)
set(${default_embedded_path_var} "@executable_path/../qtplugins/iconengines" PARENT_SCOPE)
elseif(is_QSQLDrivers)
set(${default_embedded_path_var} "@executable_path/../qtplugins/sqldrivers" PARENT_SCOPE)
elseif(is_QPlatforms)
set(${default_embedded_path_var} "@executable_path/../qtplugins/platforms" PARENT_SCOPE)
elseif(is_Lib)
set(${default_embedded_path_var} "@executable_path/../lib" PARENT_SCOPE)
else()
set(${default_embedded_path_var} "${resolved_file}" PARENT_SCOPE)
endif()
elseif(item MATCHES "[^/]+\\.framework/")
set(${default_embedded_path_var} "@executable_path/../Frameworks" PARENT_SCOPE)
endif()
endfunction()
endif()

fixup_bundle(${INPEEM_APP_PATH} "${INPEEM_LIBS}" "${INPEEM_PATHS}")
82 changes: 82 additions & 0 deletions build/cmake/inpeem_macros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
MACRO(install_plugins plugins location)
set(_files)

foreach(plugin ${plugins})
get_target_property(_loc ${plugin} LOCATION)
list(APPEND _files ${_loc})
endforeach()

install(FILES ${_files}
DESTINATION "${location}"
CONFIGURATIONS Release
COMPONENT runtime)
ENDMACRO(install_plugins)

MACRO(install_qt5_plugins location)
find_package(Qt5 COMPONENTS Sql Svg PrintSupport)

# Installing image plugins
set(_plugins Qt5::QGifPlugin Qt5::QICOPlugin Qt5::QJpegPlugin Qt5::QSvgPlugin Qt5::QTiffPlugin)
install_plugins("${_plugins}" "${location}/imageformats")

# Installing svg plugins
set(_plugins Qt5::QSvgPlugin Qt5::QSvgIconPlugin)
install_plugins("${_plugins}" "${location}/iconengines")

# Installing sql plugins
set(_plugins Qt5::QSQLiteDriverPlugin)
install_plugins("${_plugins}" "${location}/sqldrivers")

# Installing printer support plugin
if(WIN32)
set(_plugins Qt5::QWindowsPrinterSupportPlugin)
install_plugins("${_plugins}" "${location}/printsupport")
endif()

# Installing platform plugins
if(WIN32)
set(_plugins Qt5::QWindowsIntegrationPlugin Qt5::QMinimalIntegrationPlugin)
install_plugins("${_plugins}" "platforms")
elseif(APPLE)
set(_plugins Qt5::QCocoaIntegrationPlugin Qt5::QMinimalIntegrationPlugin)
install_plugins("${_plugins}" "${location}/platforms")
endif()
ENDMACRO(install_qt5_plugins)

#
# Macro installQtPlugins
#
# Description: Installs the required Qt plugins.
#
# param plugs List of the names of plugins to be installed.
#
MACRO(install_qt_plugins plgs destination)
if("${QT_PLUGINS_DIR}" STREQUAL "")
set (QT_PLUGINS_DIR "${Qt5_DIR}/../../../plugins")
endif()

set(_regex_exp "")

set(_first TRUE)

foreach(plg ${plgs})
if(NOT _first)
set (_regex_exp ${_regex_exp}|${plg})
else()
set(_regex_exp ${plg})
set(_first FALSE)
endif()
endforeach()

set(_regex_exp "(${_regex_exp})?(${CMAKE_SHARED_LIBRARY_SUFFIX})$")

set(_dest "${destination}")

set(_plugin_dirs "imageformats;iconengines;sqldrivers;platforms")

foreach(_plugin_dir ${_plugin_dirs})
install(DIRECTORY ${QT_PLUGINS_DIR}/${_plugin_dir}
DESTINATION ${_dest} COMPONENT runtime
FILES_MATCHING REGEX "${_regex_exp}")
endforeach()
ENDMACRO(install_qt_plugins)
96 changes: 78 additions & 18 deletions build/cmake/qt/modelmanager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ file(GLOB INPEEM_SRC_CPP_FILES ${INPEEM_SRC_DIR}/*.cpp)
file(GLOB INPEEM_SRC_H_FILES ${INPEEM_SRC_DIR}/*.h)
file(GLOB INPEEM_SRC_UI_FILES ${INPEEM_SRC_DIR}/ui/*.ui)
file(GLOB INPEEM_SRC_TS_FILES ${INPEEM_SRC_DIR}/ts/*.ts)
file(GLOB INPEEM_SRC_QRC_FILE ${INPEEM_SRC_DIR}/rc/resources.qrc)
file(GLOB INPEEM_SRC_QM_QRC_FILE ${INPEEM_SRC_DIR}/rc/qm/qm.qrc)
file(GLOB INPEEM_APP_ICON ${INPEEM_RESOURCES_DIR}/icon.ico)
file(GLOB INPEEM_APP_IMAGE ${INPEEM_RESOURCES_DIR}/inpeem.png)
file(GLOB INPEEM_RESOURCE_FILES ${INPEEM_APP_ICON} ${INPEEM_APP_IMAGE})
file(GLOB INPEEM_QT_RESOURCE_FILES ${INPEEM_SRC_QRC_FILE} ${INPEEM_SRC_QM_QRC_FILE})
source_group("Source Files" FILES ${INPEEM_SRC_CPP_FILES})
source_group("Header Files" FILES ${INPEEM_SRC_H_FILES})
source_group("Resource Files" FILES ${INPEEM_RESOURCE_FILES} ${INPEEM_QT_RESOURCE_FILES})
source_group("UI Files" FILES ${INPEEM_SRC_UI_FILES})
source_group("TS Files" FILES ${INPEEM_SRC_TS_FILES})

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Widgets LinguistTools REQUIRED)

qt5_wrap_ui(INPEEM_GEN_UI_FILES ${INPEEM_SRC_UI_FILES})

qt5_add_translation(INPEEM_QM_FILES ${INPEEM_SRC_TS_FILES})
Expand All @@ -26,13 +32,44 @@ execute_process(COMMAND ${QT5_QMAKE_EXECUTABLE} -query QT_INSTALL_TRANSLATIONS
file(TO_CMAKE_PATH "${qt_translations_dir}" qt_translations_dir)
set(QT_TRANSLATIONS_DIR ${qt_translations_dir} CACHE PATH "The location of the Qt translations" FORCE)

set(INPEEM_LIBRARIES ${INPEEM_LIBRARIES} Qt5::Widgets)
file(COPY ${INPEEM_SRC_QM_QRC_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
#"<RCC>\n<qresource prefix=\"\/\">\n<file>modelmanager_pt_br.qm</file>\n</qresource>\n</RCC>")

file(GLOB INPEEM_APP_ICON ${INPEEM_RESOURCES_DIR}/icon.ico)
file(GLOB INPEEM_APP_IMAGE ${INPEEM_RESOURCES_DIR}/inpeem.png)
qt5_add_resources(INPEEM_QRC_FILES ${INPEEM_SRC_QRC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/qm.qrc)

set(INPEEM_LIBRARIES ${INPEEM_LIBRARIES} Qt5::Widgets)

file(GLOB INPEEM_RESOURCE_FILES ${INPEEM_APP_ICON} ${INPEEM_APP_IMAGE})
source_group("Resource Files" FILES ${INPEEM_RESOURCE_FILES})
if(APPLE)
find_library(_COREFOUNDATION_LIBRARY NAMES CoreFoundation PATHS "/")

if(INPEEM_BUILD_AS_BUNDLE)
file(GLOB INPEEM_MACOSX_BUNDLE_ICON ${INPEEM_RESOURCES_DIR}/icon.icns)
set(INPEEM_RESOURCE_FILES ${INPEEM_RESOURCE_FILES} ${INPEEM_MACOSX_BUNDLE_ICON})
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
set(MACOSX_BUNDLE_COPYRIGHT "Copyright 2020")
set(MACOSX_BUNDLE_SIGNATURE ${PROJECT_NAME})
set(MACOSX_BUNDLE_GUI_IDENTIFIER "http://inpe-em.ccst.inpe.br")
set(MACOSX_BUNDLE_EXECUTABLE_NAME ${PROJECT_NAME})
set(MACOSX_BUNDLE_INFO_STRING "INPE – Emission Model")
set(MACOSX_BUNDLE_ICON_FILE icon.icns)
set(MACOSX_BUNDLE_LONG_VERSION_STRING ${INPEEM_VERSION})
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${INPEEM_VERSION_MAJOR})
set(MACOSX_BUNDLE_BUNDLE_VERSION ${INPEEM_VERSION})

#set(APP_ICON_MACOSX ${INPEEM_MACOSX_BUNDLE_ICON})
set_source_files_properties(${INPEEM_MACOSX_BUNDLE_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")

configure_file(${CMAKE_ROOT}/Modules/MacOSXBundleInfo.plist.in ${CMAKE_BINARY_DIR}/Info.plist)

set(CPACK_PACKAGE_ICON ${INPEEM_MACOSX_BUNDLE_ICON})
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
set(CPACK_BUNDLE_ICON ${CPACK_PACKAGE_ICON})
set(CPACK_BUNDLE_PLIST ${CMAKE_BINARY_DIR}/Info.plist)

set(INPEEM_APP_TYPE MACOSX_BUNDLE)
endif()
else()
endif()

include_directories(${INPEEM_SRC_DIR}
#${INPEEM_RESOURCES_DIR}
Expand All @@ -41,9 +78,10 @@ include_directories(${INPEEM_SRC_DIR}
set(INPEEM_FILES ${INPEEM_SRC_CPP_FILES} ${INPEEM_SRC_H_FILES}
${INPEEM_GEN_UI_FILES}
${INPEEM_RESOURCE_FILES}
${INPEEM_QM_FILES})
#${INPEEM_QM_FILES}
${INPEEM_QRC_FILES})

add_executable(${PROJECT_NAME} ${INPEEM_FILES})
add_executable(${PROJECT_NAME} ${INPEEM_APP_TYPE} ${INPEEM_FILES})
target_link_libraries(${PROJECT_NAME} ${INPEEM_LIBRARIES})
#target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets)

Expand All @@ -62,22 +100,48 @@ install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION . COMPONENT runtime
BUNDLE DESTINATION . COMPONENT runtime)

if(APPLE AND INPEEM_BUILD_AS_BUNDLE)
set(INPEEM_BASE_LOCATION ${MACOSX_BUNDLE_BUNDLE_NAME}.app/Contents)
set(INPEEM_RUNTIME_LOCATION ${INPEEM_BASE_LOCATION}/MacOS)
set(INPEEM_LIBRARY_LOCATION ${INPEEM_BASE_LOCATION}/lib)
set(INPEEM_RESOURCE_LOCATION ${INPEEM_BASE_LOCATION}/Resources)
set(INPEEM_TERRAME_PACKAGES_DIR ${INPEEM_BASE_LOCATION}/terrame/terrame.app/Contents/MacOS/packages)
set(INPEEM_QT_PLUGINS_LOCATION ${INPEEM_BASE_LOCATION}/qtplugins)
install_qt5_plugins(${INPEEM_QT_PLUGINS_LOCATION})
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/qt.conf
"[Paths]\nBinaries = MacOS\nPlugins = qtplugins")

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qt.conf
DESTINATION ${INPEEM_RESOURCE_LOCATION}
COMPONENT runtime)
else()
set(INPEEM_BASE_LOCATION .)
set(INPEEM_RUNTIME_LOCATION ${INPEEM_BASE_LOCATION})
set(INPEEM_LIBRARY_LOCATION ${INPEEM_BASE_LOCATION})
set(INPEEM_RESOURCE_LOCATION ${INPEEM_BASE_LOCATION})
set(INPEEM_TERRAME_PACKAGES_DIR ${INPEEM_BASE_LOCATION}/terrame/bin/packages)
endif()

install(FILES ${INPEEM_RESOURCE_FILES}
DESTINATION .
DESTINATION ${INPEEM_RESOURCE_LOCATION}
COMPONENT runtime)

set(INPEEM_DOC_DIR ${INPEEM_ROOT_DIR}/doc)
file(GLOB INPEEM_DOC_FILES ${INPEEM_DOC_DIR}/*.chm)
install(FILES ${INPEEM_DOC_FILES}
DESTINATION .
COMPONENT runtime)
DESTINATION ${INPEEM_RESOURCE_LOCATION}
COMPONENT runtime)

install(FILES ${INPEEM_QM_FILES}
DESTINATION ${INPEEM_RESOURCE_LOCATION}/langs
COMPONENT runtime)

install(DIRECTORY ${INPEEM_TERRAME_DIR}
DESTINATION .
DESTINATION ${INPEEM_BASE_LOCATION}
COMPONENT runtime)

set(INPEEM_LUA_DIR ${INPEEM_ROOT_DIR}/src/terrame/)
set(INPEEM_PACKAGE_DIR terrame/bin/packages/inpeem)
set(INPEEM_PACKAGE_DIR ${INPEEM_TERRAME_PACKAGES_DIR}/inpeem)
install(DIRECTORY ${INPEEM_LUA_DIR}
DESTINATION ${INPEEM_PACKAGE_DIR}
COMPONENT runtime)
Expand Down Expand Up @@ -127,11 +191,7 @@ if(WIN32)
DESTINATION ./platforms
COMPONENT runtime
CONFIGURATIONS Release)
endif()

install(FILES ${INPEEM_QM_FILES}
DESTINATION ./langs
COMPONENT runtime)
endif()

configure_file(${PROJECT_SOURCE_DIR}/inpeem_version.h.in
${INPEEM_SRC_DIR}/Version.h @ONLY)
Expand Down
63 changes: 63 additions & 0 deletions build/scripts/mac/inpeem_conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

if [ "$_INPEEM_BUILD_DIR" == "" ]; then
_INPEEM_BUILD_DIR=$(pwd)/build
fi
export _INPEEM_BUILD_DIR=$_INPEEM_BUILD_DIR

if [ "$_INPEEM_INSTALL_DIR" == "" ]; then
_INPEEM_INSTALL_DIR=$(pwd)/install
fi
export _INPEEM_INSTALL_DIR=$_INPEEM_INSTALL_DIR

if [ "$_INPEEM_BUILD_TYPE" == "" ]; then
_INPEEM_BUILD_TYPE=Release
fi
export _INPEEM_BUILD_TYPE=$_INPEEM_BUILD_TYPE

if [ "$_INPEEM_BUILD_AS_BUNDLE" == "" ]; then
_INPEEM_BUILD_AS_BUNDLE=ON
fi
export _INPEEM_BUILD_AS_BUNDLE=$_INPEEM_BUILD_AS_BUNDLE

if [ "$_INPEEM_CREATE_INSTALLER" == "" ]; then
_INPEEM_CREATE_INSTALLER=OFF
fi
export _INPEEM_CREATE_INSTALLER=$_INPEEM_CREATE_INSTALLER

if [ "$_INPEEM_TERRAME_DIR" == "" ]; then
_INPEEM_TERRAME_DIR=/Users/developer/inpeem/3rdparty/terrame
fi
export _INPEEM_TERRAME_DIR=$_INPEEM_TERRAME_DIR

if [ "$_Qt5_DIR" == "" ]; then
_Qt5_DIR=/Users/developer/Qt5.6.0/5.6/clang_64/lib/cmake
fi
export _Qt5_DIR=$_Qt5_DIR

if ! command -v qmake &> /dev/null; then
export PATH=$PATH:/Users/developer/Qt5.6.0/5.6/clang_64/bin
fi

if ! command -v cmake &> /dev/null; then
export PATH=$PATH:export PATH=$PATH:/Applications/CMake.app/Contents/bin
fi

export _INPEEM_SOLUTION_DIR=$(pwd)

mkdir $_INPEEM_BUILD_DIR
cd $_INPEEM_BUILD_DIR

if [ "$_INPEEM_GIT_DIR" == "" ]; then
_INPEEM_GIT_DIR=../../git/inpeem
fi
export _INPEEM_GIT_DIR=$_INPEEM_GIT_DIR

cmake -G "Xcode" -C $_INPEEM_GIT_DIR/build/cmake/inpeem_build_conf.cmake $_INPEEM_GIT_DIR/build/cmake
cmake --build . --target install --config $_INPEEM_BUILD_TYPE

if [ "$_INPEEM_CREATE_INSTALLER" == "ON" ]; then
cpack -D CPACK_GENERATOR="DragNDrop" -C Release --config ./CPackConfig.cmake
fi

cd $_INPEEM_SOLUTION_DIR
Binary file added resources/icon.icns
Binary file not shown.
2 changes: 1 addition & 1 deletion src/qt/modelmanager/CentralWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ qt::modelmanager::CentralWidget::CentralWidget(QWidget *parent) :
{
ui->setupUi(this);

QPixmap img("inpeem.png");
QPixmap img(":/img/inpeem.png");
ui->label->setPixmap(img.scaled(QSize(250, 250), Qt::KeepAspectRatio, Qt::SmoothTransformation));

QTabWidget *tabWidget = new QTabWidget(this);
Expand Down
Loading

0 comments on commit 03850c5

Please sign in to comment.