Skip to content

Commit

Permalink
ENH: Packaging for LINUX
Browse files Browse the repository at this point in the history
  • Loading branch information
juanprietob committed Mar 22, 2019
1 parent b6b1271 commit 00c845c
Showing 1 changed file with 93 additions and 91 deletions.
184 changes: 93 additions & 91 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ if(APPLE)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

if(UNIX AND NOT APPLE AND CREATE_BUNDLE)
# the RPATH to be used when installing
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../lib;../lib")
endif()

# generate FADTTSter executable
SEMMacroBuildCLI(
NAME FADTTSter
Expand All @@ -77,9 +82,6 @@ INSTALL_LIBRARY_DESTINATION ${INSTALL_LIBRARY_DESTINATION}
INSTALL_ARCHIVE_DESTINATION ${INSTALL_ARCHIVE_DESTINATION}
)


set(FADTTS_LIBRARIES ${FADTTS_LIBRARIES} ${cli_executable_libraries} )

# get FADTTSter info
FILE(READ FADTTSter.xml var)

Expand All @@ -101,22 +103,22 @@ add_definitions(-DFADTTS_CONTRIBUTORS="${contributors}")
# Generate a bundle
if(CREATE_BUNDLE)

if(APPLE)
set(OS_BUNDLE MACOSX_BUNDLE)
elseif(WIN32)
set(OS_BUNDLE WIN32)
endif()

set(bundle_name FADTTSter${version})

#--------------------------------------------------------------------------------
SET(qtconf_dest_dir bin)
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${bundle_name}")

set(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Icons/logoFADTTSter_small.icns)
set(CPACK_PACKAGE_ICON "${myApp_ICON}")

IF(APPLE)
string(REPLACE "." ";" VERSION_LIST ${version})
list(GET VERSION_LIST 0 CPACK_PACKAGE_VERSION_MAJOR)
list(GET VERSION_LIST 1 CPACK_PACKAGE_VERSION_MINOR)
list(GET VERSION_LIST 2 CPACK_PACKAGE_VERSION_PATCH)

set(bundle_name FADTTSter${version})

if(APPLE)
set(OS_BUNDLE MACOSX_BUNDLE)
#--------------------------------------------------------------------------------
SET(qtconf_dest_dir bin)
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${bundle_name}")

SET(qtconf_dest_dir ${bundle_name}.app/Contents/Resources)
SET(APPS "\${CMAKE_INSTALL_PREFIX}/${bundle_name}.app")

Expand All @@ -137,83 +139,66 @@ if(CREATE_BUNDLE)
get_filename_component(apple_icon_filename ${myApp_ICON} NAME)
set(MACOSX_BUNDLE_ICON_FILE ${apple_icon_filename})

add_executable(${bundle_name} ${OS_BUNDLE}
${myApp_ICON} ${FADTTS_src}
)
target_link_libraries(${bundle_name} ${QT_LIBRARIES} ${VTK_LIBRARIES})

#--------------------------------------------------------------------------------
# Install the QtTest application, on Apple, the bundle is at the root of the
# install tree, and on other platforms it'll go into the bin directory.
INSTALL(TARGETS ${bundle_name}
DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
)

macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
if(EXISTS "${_qt_plugin_path}")
get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
set(_qt_plugin_dest "${bundle_name}.app/Contents/PlugIns/${_qt_plugin_type}")
install(FILES "${_qt_plugin_path}"
DESTINATION "${_qt_plugin_dest}"
COMPONENT Runtime)
set(${_qt_plugins_var}
"${${_qt_plugins_var}};\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}")
else()
message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
endif()
endmacro()

install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)

# To Create a package, one can run "cpack -G DragNDrop CPackConfig.cmake" on Mac OS X
# where CPackConfig.cmake is created by including CPack
# And then there's ways to customize this as well
set(CPACK_BINARY_DRAGNDROP ON)
#--------------------------------------------------------------------------------
# install a qt.conf file
# this inserts some cmake code into the install script to write the file
INSTALL(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]\nPlugins = PlugIns\n\")
" COMPONENT Runtime)

# Install the license
INSTALL(FILES
${CMAKE_SOURCE_DIR}/LICENSE
DESTINATION "${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}"
COMPONENT Runtime)

get_target_property(Qt5_location Qt5::Widgets LOCATION)
string(FIND ${Qt5_location} "/QtWidgets" length)
string(SUBSTRING ${Qt5_location} 0 ${length} Qt5_location)
#Fix the bundle
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"${QT_PLUGINS};\" \"${Qt5_location}\")
"
COMPONENT Runtime)
ENDIF(APPLE)

IF(WIN32)
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${bundle_name}.exe")
ENDIF(WIN32)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(${bundle_name} ${OS_BUNDLE}
${myApp_ICON} ${FADTTS_src}
)
target_link_libraries(${bundle_name} ${QT_LIBRARIES} ${VTK_LIBRARIES})

#--------------------------------------------------------------------------------
# Install the QtTest application, on Apple, the bundle is at the root of the
# install tree, and on other platforms it'll go into the bin directory.
INSTALL(TARGETS ${bundle_name}
DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
)

macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
if(EXISTS "${_qt_plugin_path}")
get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
set(_qt_plugin_dest "${bundle_name}.app/Contents/PlugIns/${_qt_plugin_type}")
install(FILES "${_qt_plugin_path}"
DESTINATION "${_qt_plugin_dest}"
COMPONENT Runtime)
set(${_qt_plugins_var}
"${${_qt_plugins_var}};\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}")
else()
message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
endif()
endmacro()

install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)

#--------------------------------------------------------------------------------
# install a qt.conf file
# this inserts some cmake code into the install script to write the file
INSTALL(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]\nPlugins = PlugIns\n\")
" COMPONENT Runtime)

# Install the license
INSTALL(FILES
${CMAKE_SOURCE_DIR}/LICENSE
DESTINATION "${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}"
COMPONENT Runtime)

get_target_property(Qt5_location Qt5::Widgets LOCATION)
string(FIND ${Qt5_location} "/QtWidgets" length)
string(SUBSTRING ${Qt5_location} 0 ${length} Qt5_location)
#Fix the bundle
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"${QT_PLUGINS};\" \"${Qt5_location}\")
"
COMPONENT Runtime)

# To Create a package, one can run "cpack -G DragNDrop CPackConfig.cmake" on Mac OS X
# where CPackConfig.cmake is created by including CPack
# And then there's ways to customize this as well
set(CPACK_BINARY_DRAGNDROP ON)

endif()


if(UNIX)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# the RPATH to be used when installing
SET(CMAKE_INSTALL_RPATH "../lib")

get_target_property(QtWidgets_location Qt5::Widgets LOCATION)
get_target_property(QtOpenGL_location Qt5::OpenGL LOCATION)

Expand All @@ -232,6 +217,23 @@ if(UNIX)
DESTINATION lib
COMPONENT Runtime)

if(UNIX AND NOT APPLE)

get_target_property(QtSql_location Qt5::Sql LOCATION)
get_target_property(QtX11Extras_location Qt5::X11Extras LOCATION)
get_target_property(QCore_location Qt5::Core LOCATION)
get_target_property(QGui_location Qt5::Gui LOCATION)

get_target_property(QtSql_SOFT Qt5::Sql IMPORTED_SONAME_RELEASE)
get_target_property(QtX11Extras_SOFT Qt5::X11Extras IMPORTED_SONAME_RELEASE)
get_target_property(QCore_SOFT Qt5::Core IMPORTED_SONAME_RELEASE)
get_target_property(QGui_SOFT Qt5::Gui IMPORTED_SONAME_RELEASE)


install(FILES ${QtSql_location} ${QtX11Extras_location} ${QCore_location} ${QGui_location} ${Qt5_location}/${QtWidgets_SOFT} ${Qt5_location}/${QtSql_SOFT} ${Qt5_location}/${QtX11Extras_SOFT} ${Qt5_location}/${QCore_SOFT} ${Qt5_location}/${QGui_SOFT}
DESTINATION lib
COMPONENT Runtime)
endif()
endif()

# To Create a package, one can run "cpack -G DragNDrop CPackConfig.cmake" on Mac OS X
Expand Down

0 comments on commit 00c845c

Please sign in to comment.