Commit 37068cbd authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

REFAC: cmake macros for mingw package

parent fb6f6e4f
macro(package_mingw)
cmake_parse_arguments(PACKAGE "" "PREFIX_DIR;ARCH;MXEROOT" "SEARCHDIRS;PEFILES" ${ARGN} )
if("${PACKAGE_ARCH}" STREQUAL "x86")
set(MXE_BIN_DIR "${PACKAGE_MXEROOT}/usr/i686-w64-mingw32.shared/bin")
set(MXE_OBJDUMP "${PACKAGE_MXEROOT}/usr/bin/i686-w64-mingw32.shared-objdump")
elseif("${PACKAGE_ARCH}" STREQUAL "x64")
set(MXE_BIN_DIR "${PACKAGE_MXEROOT}/usr/x86_64-w64-mingw32.shared/bin")
set(MXE_OBJDUMP "${PACKAGE_MXEROOT}/usr/bin/x86_64-w64-mingw32.shared-objdump")
cmake_parse_arguments(PKG "" "STAGE_DIR;ARCH;MXEROOT" "SEARCHDIRS" ${ARGN} )
if("${PKG_ARCH}" STREQUAL "x86")
set(DEPENDENCIES_INSTALL_DIR "${PKG_MXEROOT}/usr/i686-w64-mingw32.shared")
set(MXE_OBJDUMP "${PKG_MXEROOT}/usr/bin/i686-w64-mingw32.shared-objdump")
elseif("${PKG_ARCH}" STREQUAL "x64")
set(DEPENDENCIES_INSTALL_DIR "${PKG_MXEROOT}/usr/x86_64-w64-mingw32.shared")
set(MXE_OBJDUMP "${PKG_MXEROOT}/usr/bin/x86_64-w64-mingw32.shared-objdump")
endif()
# message()
#guess install directory from OTB_MODULES_DIR
set(OTB_INSTALL_DIR ${OTB_MODULES_DIR}/../../../..)
set(OTB_APPLICATIONS_DIR ${OTB_MODULES_DIR}/../../../../lib/otb/applications)
set(OTB_APPLICATIONS_DIR ${OTB_MODULES_DIR}/../../../otb/applications)
set(MXE_BIN_DIR "${DEPENDENCIES_INSTALL_DIR}/bin")
file(GLOB MXE_GCC_LIB_DIR "${MXE_BIN_DIR}/gcc*")
list(APPEND PACKAGE_SEARCHDIRS ${MXE_GCC_LIB_DIR})
list(APPEND PACKAGE_SEARCHDIRS ${MXE_BIN_DIR})
list(APPEND PACKAGE_SEARCHDIRS "${MXE_BIN_DIR}/../qt/bin") #Qt
list(APPEND PACKAGE_SEARCHDIRS "${MXE_BIN_DIR}/../qt/lib") #Qwt
list(APPEND PACKAGE_SEARCHDIRS "${CMAKE_INSTALL_PREFIX}/bin") #mvd
list(APPEND PACKAGE_SEARCHDIRS "${OTB_APPLICATIONS_DIR}") #otb apps
list(APPEND PACKAGE_SEARCHDIRS "${OTB_INSTALL_DIR}/bin") #otbApplicationLauncher*.exe
list(APPEND PKG_SEARCHDIRS ${MXE_GCC_LIB_DIR})
list(APPEND PKG_SEARCHDIRS ${MXE_BIN_DIR})
list(APPEND PKG_SEARCHDIRS "${MXE_BIN_DIR}/../qt/bin") #Qt
list(APPEND PKG_SEARCHDIRS "${MXE_BIN_DIR}/../qt/lib") #Qwt
list(APPEND PKG_SEARCHDIRS "${CMAKE_INSTALL_PREFIX}/bin") #mvd
list(APPEND PKG_SEARCHDIRS "${OTB_APPLICATIONS_DIR}") #otb apps
list(APPEND PKG_SEARCHDIRS "${OTB_INSTALL_DIR}/bin") #otbApplicationLauncher*.exe
if(NOT PACKAGE_PEFILES)
list(APPEND PACKAGE_PEFILES "${CMAKE_INSTALL_PREFIX}/bin/monteverdi.exe")
list(APPEND PACKAGE_PEFILES "${CMAKE_INSTALL_PREFIX}/bin/mapla.exe")
list(APPEND PACKAGE_PEFILES "${OTB_INSTALL_DIR}/bin/otbApplicationLauncherCommandLine.exe")
list(APPEND PACKAGE_PEFILES "${OTB_INSTALL_DIR}/bin/otbApplicationLauncherQt.exe") #OTBQtWidget must exists when you are building OTB
clear_package_staging_directory()
if(EXISTS "${OTB_INSTALL_DIR}/bin/iceViewer.exe")
list(APPEND PACKAGE_PEFILES "${OTB_INSTALL_DIR}/bin/iceViewer.exe") #iceviewer
endif()
endif()
install_common(${PACKAGE_PREFIX_DIR})
#dependency resolution based on copydlldeps.sh from mxe by Timothy Gu
file(GLOB otbapps_list ${OTB_APPLICATIONS_DIR}/otbapp_*dll) # /lib/otb
list(APPEND PACKAGE_PEFILES ${otbapps_list})
set(alldlls)
set(notfound_dlls)
foreach(infile ${PACKAGE_PEFILES})
get_filename_component(bn ${infile} NAME)
process_deps(${bn})
endforeach()
list(LENGTH notfound_dlls nos)
if(${nos} GREATER 0)
string(REPLACE ".dll" ".dll," notfound ${notfound_dlls})
message(FATAL_ERROR "Following dlls were not found: ${notfound}
Please consider adding their paths to SEARCHDIRS when calling package_mingw macro.")
endif()
set(PKG_PEFILES)
configure_package()
endmacro(package_mingw)
set(SYSTEM_DLLS
msvc.*dll
user32.dll
gdi32.dll
shell32.dll
kernel32.dll
advapi32.dll
crypt32.dll
ws2_32.dll
wldap32.dll
ole32.dll
opengl32.dll
glu32.dll
comdlg32.dll
imm32.dll
oleaut32.dll
comctl32.dll
winmm.dll
shfolder.dll
secur32.dll
wsock32.dll
winspool.drv)
## http://www.cmake.org/Wiki/CMakeMacroListOperations
macro(is_system_dll matched value)
set(${matched})
string(TOLOWER ${value} value_)
foreach (pattern ${SYSTEM_DLLS})
string(TOLOWER ${pattern} pattern_)
if(${value_} MATCHES ${pattern_})
set(${matched} TRUE)
endif()
endforeach()
endmacro()
macro(list_contains var value)
set(${var})
foreach(value2 ${ARGN})
if(${value} STREQUAL ${value2})
set(${var} TRUE)
else()
string(TOLOWER ${value} value_)
string(TOLOWER ${value2} value2_)
if(${value_} STREQUAL ${value2_})
set(${var} TRUE)
endif()
endif()
endforeach(value2)
endmacro()
function(process_deps infile)
......@@ -112,7 +39,7 @@ function(process_deps infile)
list_contains(contains "${bn}" "${alldlls}")
if(NOT contains)
set(DLL_FOUND FALSE)
foreach(SEARCHDIR ${PACKAGE_SEARCHDIRS})
foreach(SEARCHDIR ${PKG_SEARCHDIRS})
if(NOT DLL_FOUND)
if(EXISTS ${SEARCHDIR}/${infile})
set(DLL_FOUND TRUE)
......@@ -127,7 +54,7 @@ function(process_deps infile)
message(STATUS "Processing ${SEARCHDIR}/${infile}")
if(NOT "${infile}" MATCHES "otbapp")
install(FILES "${SEARCHDIR}/${infile}"
DESTINATION ${PACKAGE_PREFIX_DIR}/bin)
DESTINATION ${PKG_STAGE_DIR}/bin)
else()
##message(STATUS "skipping..${infile}")
endif()
......
set(WINDOWS_SYSTEM_DLLS
msvc.*dll
user32.dll
gdi32.dll
shell32.dll
kernel32.dll
advapi32.dll
crypt32.dll
ws2_32.dll
wldap32.dll
ole32.dll
opengl32.dll
glu32.dll
comdlg32.dll
imm32.dll
oleaut32.dll
comctl32.dll
winmm.dll
shfolder.dll
secur32.dll
wsock32.dll
winspool.drv)
SET(UNIX_SYSTEM_DLLS
libm.so
libc.so
libstdc*
libgcc_s.so
librt.so
libdl.so
libpthread.so
libidn.so
libgomp.so*
ld-linux-x86-64.so*
libX11.so*
libXext.so*
libXau.so*
libXdmcp.so*
libXxf86vm.so*
libdrm.so.2
libGL.so*
libGLU.so*
)
set(SYSTEM_DLLS "${UNIX_SYSTEM_DLLS}")
if(WIN32 OR CMAKE_CROSSCOMPILING)
set(SYSTEM_DLLS "${WINDOWS_SYSTEM_DLLS}")
endif()
## http://www.cmake.org/Wiki/CMakeMacroListOperations
macro(is_system_dll matched value)
set(${matched})
string(TOLOWER ${value} value_)
foreach (pattern ${SYSTEM_DLLS})
string(TOLOWER ${pattern} pattern_)
if(${value_} MATCHES ${pattern_})
set(${matched} TRUE)
endif()
endforeach()
endmacro()
macro(list_contains var value)
set(${var})
foreach(value2 ${ARGN})
if(${value} STREQUAL ${value2})
set(${var} TRUE)
endif()
endforeach(value2)
endmacro()
# Get the translation files coming with Qt, and install them in the bundle
# They are loaded by Monteverdi.
function(get_qt_translation_files RESULT)
......@@ -15,53 +84,32 @@ function(get_qt_translation_files RESULT)
set(${RESULT} ${translation_files} PARENT_SCOPE)
endfunction()
function(install_common outdir)
function(install_common include_mvd)
#a convenient cmake var for storing <prefix>
set(PKG_PREFIX_DIR "${outdir}")
# set(PKG_STAGE_DIR "${stage_dir}")
#a convenient cmake var for storing <prefix>/bin
set(PKG_BIN_DIR "${PKG_PREFIX_DIR}/bin")
#name of qt's sqlite plugin. Varies with platform/OS
set(PKG_QTSQLITE_FILENAME "qsqlite4.dll")
#root folder where qt plugins are installed
set(PKG_QTPLUGINS_DIR "${PKG_PREFIX_DIR}/lib/qt4/plugins")
set(PKG_STAGE_BIN_DIR "${PKG_STAGE_DIR}/bin")
#root folder where otb applications are installed
set(PKG_OTBLIBS_DIR "${PKG_PREFIX_DIR}/lib/otb")
#qt4's distributes some translation of common message string used in Qt.
#This are provided with any qt installation. We reuse them in otb package
#so as not to reinvent the wheels.
set(PKG_I18N_DIR "${PKG_PREFIX_DIR}/lib/qt4/translations")
#<prefix>/share for otb i18n directory. This is different from qt's i18N directory
#which is <prefix>/share/qt4/translations.
set(PKG_OTB_I18N_DIR "${PACKAGE_PREFIX_DIR}/${Monteverdi_INSTALL_DATA_DIR}/i18n")
set(PKG_OTBLIBS_DIR "${PKG_STAGE_DIR}/lib/otb")
#<prefix>/share for gdal data files
set(PKG_DATA_DIR "${PKG_PREFIX_DIR}/share")
set(PKG_SHARE_DEST_DIR ${PKG_STAGE_DIR}/share)
#place to install where qt.conf
set(PKG_QTCONF_DIR "${CMAKE_INSTALL_PREFIX}/${PKG_BIN_DIR}")
set(PKG_SHARE_SOURCE_DIR ${DEPENDENCIES_INSTALL_DIR}/share)
#a convenient cmake var to store the otb's install prefix
#guess install directory from OTB_MODULES_DIR
set(OTB_INSTALL_DIR ${OTB_MODULES_DIR}/../../../..)
if(NOT OTB_APPS_LIST)
message(FATAL_ERROR "you must set 'OTB_APPS_LIST' before calling this method")
endif()
# Just check if required variables are defined.
foreach(req
Monteverdi_SOURCE_DIR
Monteverdi_BINARY_DIR
MXE_BIN_DIR
OTB_MODULES_DIR
PACKAGE_PEFILES
QT_PLUGINS_DIR
DEPENDENCIES_INSTALL_DIR
OTB_APPLICATIONS_DIR
PKG_STAGE_DIR
CMAKE_INSTALL_PREFIX
PKG_QTCONF_DIR
OTB_INSTALL_DIR
)
if(NOT DEFINED ${req})
......@@ -71,7 +119,7 @@ function(install_common outdir)
endforeach(req)
#one for debugging..
install(CODE "message(\"CMake/PackageHelper.cmake:install_common(${outdir})\n${vars}\n\")")
# install(CODE "message(\"CMake/PackageHelper.cmake:install_common(${outdir})\n${vars}\n\")")
####################### install cli and gui scripts ###########################
file(GLOB PKG_APP_SCRIPTS
......@@ -83,33 +131,85 @@ function(install_common outdir)
message(WARNING "PKG_APP_SCRIPTS is empty: ${PKG_APP_SCRIPTS}")
endif()
install(FILES ${PKG_APP_SCRIPTS}
DESTINATION ${PKG_BIN_DIR})
foreach(exe_file ${PACKAGE_PEFILES})
#check ext is .exe
get_filename_component(FILE_EXT ${exe_file} EXT)
string(TOLOWER ${FILE_EXT} file_ext)
if( ${file_ext} STREQUAL ".exe")
get_filename_component(base_name ${exe_file} NAME_WE)
#check if a .bat exists?
if(EXISTS ${Monteverdi_SOURCE_DIR}/Packaging/Windows/${base_name}.bat)
install(FILES ${Monteverdi_SOURCE_DIR}/Packaging/Windows/${base_name}.bat
DESTINATION ${PKG_BIN_DIR})
endif()
##################### install cli and gui scripts #######################
install(FILES ${PKG_APP_SCRIPTS} DESTINATION ${PKG_STAGE_BIN_DIR})
if(include_mvd)
install_monteverdi_files()
endif()
####################### install GDAL data ############################
set(GDAL_DATA ${PKG_SHARE_SOURCE_DIR}/gdal)
if(NOT EXISTS "${GDAL_DATA}/epsg.wkt")
message(FATAL_ERROR "Cannot generate package without GDAL_DATA : ${GDAL_DATA} ${DEPENDENCIES_INSTALL_DIR}")
endif()
install(DIRECTORY ${GDAL_DATA} DESTINATION ${PKG_SHARE_DEST_DIR})
####################### install GeoTIFF data ###########################
install(DIRECTORY ${PKG_SHARE_SOURCE_DIR}/epsg_csv DESTINATION ${PKG_SHARE_DEST_DIR})
####################### install OSSIM data ###########################
install(DIRECTORY ${PKG_SHARE_SOURCE_DIR}/ossim DESTINATION ${PKG_SHARE_DEST_DIR})
####################### Install otb applications ######################
install(DIRECTORY "${OTB_APPLICATIONS_DIR}" DESTINATION ${PKG_OTBLIBS_DIR})
endfunction()
function(install_monteverdi_files)
#name/ext of qt's sqlite plugin. Varies with platform/OS
if(WIN32 OR CMAKE_CROSSCOMPILING)
set(PKG_QTSQLITE_FILENAME "qsqlite4.dll")
elseif(APPLE)
set(PKG_QTSQLITE_FILENAME "qsqlite.dylib")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT CMAKE_CROSSCOMPILING)
set(PKG_QTSQLITE_FILENAME "libqsqlite.so")
else()
message(FATAL_ERROR "install_monteverdi_files: Unknown OS/Platform")
endif()
#root folder where qt plugins are installed
set(PKG_QTPLUGINS_DIR "${PKG_STAGE_DIR}/lib/qt4/plugins")
#qt4's distributes some translation of common message string used in Qt.
#This are provided with any qt installation. We reuse them in otb package
#so as not to reinvent the wheels.
set(PKG_I18N_DIR "${PKG_STAGE_DIR}/lib/qt4/translations")
#<prefix>/share for otb i18n directory. This is different from qt's i18N directory
#which is <prefix>/share/qt4/translations.
set(PKG_OTB_I18N_DIR "${PKG_STAGE_DIR}/${Monteverdi_INSTALL_DATA_DIR}/i18n")
# Just check if required variables are defined.
foreach(req
Monteverdi_SOURCE_DIR
QT_PLUGINS_DIR
PKG_STAGE_BIN_DIR
PKG_QTSQLITE_FILENAME
PKG_QTPLUGINS_DIR
PKG_I18N_DIR
PKG_OTB_I18N_DIR
)
if(NOT DEFINED ${req} OR "${${req}}" STREQUAL "")
message(FATAL_ERROR "you must set ${req} before calling this method")
endif()
endforeach()
set(vars "${vars} ${req}=[${${req}}]\n")
endforeach(req)
#message("CMake/PackageHelper.cmake:install_common(${stage_dir})\n${vars}\n")
##################### install mingw otbenv.cmd ##########################
if(EXISTS ${Monteverdi_SOURCE_DIR}/Packaging/Windows/mingw/otbenv.cmd)
install(FILES ${Monteverdi_SOURCE_DIR}/Packaging/Windows/mingw/otbenv.cmd
DESTINATION ${PKG_PREFIX_DIR})
DESTINATION ${PKG_STAGE_DIR})
endif()
####################### install mingw qt.conf ##########################
if(EXISTS ${Monteverdi_SOURCE_DIR}/Packaging/Windows/mingw/qt.conf)
install(FILES ${Monteverdi_SOURCE_DIR}/Packaging/Windows/mingw/qt.conf
DESTINATION ${PKG_BIN_DIR})
DESTINATION ${PKG_STAGE_BIN_DIR})
endif()
####################### install sqldriver plugin ########################
......@@ -121,8 +221,7 @@ function(install_common outdir)
get_qt_translation_files(QT_TRANSLATIONS_FILES)
#install all files in ${QT_TRANSLATIONS_FILES}
install(FILES ${QT_TRANSLATIONS_FILES}
DESTINATION ${PKG_I18N_DIR})
install(FILES ${QT_TRANSLATIONS_FILES} DESTINATION ${PKG_I18N_DIR})
#translation of monteverdi specific strings
file(GLOB APP_TS_FILES ${Monteverdi_SOURCE_DIR}/i18n/*.ts) # qm files
......@@ -132,23 +231,74 @@ function(install_common outdir)
DESTINATION ${PKG_OTB_I18N_DIR})
endforeach()
####################### install GDAL data ############################
set(GDAL_DATA ${MXE_BIN_DIR}/../share/gdal)
if(NOT EXISTS "${GDAL_DATA}/epsg.wkt")
message(FATAL_ERROR "Cannot generate package without GDAL_DATA : ${GDAL_DATA} ${MXE_BIN_DIR}")
endfunction()
macro(clear_package_staging_directory)
message(STATUS "Clearing package staging directory: ${CMAKE_INSTALL_PREFIX}/${PKG_STAGE_DIR}")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_INSTALL_PREFIX}/${PKG_STAGE_DIR}")
endmacro()
function(configure_package)
set(EXE_EXT "")
set(LIB_EXT "*so")
set(SCR_EXT ".sh")
if(WIN32 OR CMAKE_CROSSCOMPILING)
set(EXE_EXT ".exe")
set(LIB_EXT "*dll")
set(SCR_EXT ".bat")
endif()
foreach(EXE_FILE
monteverdi
mapla)
if(EXISTS "${CMAKE_INSTALL_PREFIX}/bin/${EXE_FILE}${EXE_EXT}")
list(APPEND PKG_PEFILES
"${CMAKE_INSTALL_PREFIX}/bin/${EXE_FILE}${EXE_EXT}")
endif()
if(DEFINED Monteverdi_SOURCE_DIR)
if(EXISTS ${Monteverdi_SOURCE_DIR}/Packaging/Windows/${EXE_FILE}${SCR_EXT})
install(FILES
${Monteverdi_SOURCE_DIR}/Packaging/Windows/${EXE_FILE}${SCR_EXT}
DESTINATION
"${PKG_STAGE_DIR}/bin")
endif()
endif()
install(DIRECTORY ${GDAL_DATA}
DESTINATION ${PKG_DATA_DIR})
endforeach()
####################### Check otb applications ########################
file(GLOB OTB_APPS_LIST ${OTB_MODULES_DIR}/../../../otb/applications/otbapp_*dll) # /lib/otb
if(NOT OTB_APPS_LIST)
message(FATAL_ERROR "No OTB-applications detected")
foreach(EXE_FILE otbApplicationLauncherQt
iceViewer
otbTestDriver
otbApplicationLauncherCommandLine)
if(EXISTS "${OTB_INSTALL_DIR}/bin/${EXE_FILE}${EXE_EXT}")
list(APPEND PKG_PEFILES
"${OTB_INSTALL_DIR}/bin/${EXE_FILE}${EXE_EXT}")
endif()
endforeach()
file(GLOB OTB_APPS_LIST ${OTB_APPLICATIONS_DIR}/otbapp_${LIB_EXT}) # /lib/otb
set(include_mvd 0)
if(DEFINED Monteverdi_SOURCE_DIR)
set(include_mvd 1)
endif()
####################### Install otb applications ######################
install(DIRECTORY "${OTB_MODULES_DIR}/../../../otb/applications"
DESTINATION ${PKG_OTBLIBS_DIR})
install_common(${include_mvd})
endfunction()
list(APPEND PKG_PEFILES ${OTB_APPS_LIST})
set(alldlls)
set(notfound_dlls)
foreach(infile ${PKG_PEFILES})
get_filename_component(bn ${infile} NAME)
process_deps(${bn})
endforeach()
list(LENGTH notfound_dlls nos)
if(${nos} GREATER 0)
STRING(REPLACE ".so;" ".so," notfound ${notfound_dlls})
message(FATAL_ERROR "Following dlls were not found: ${notfound_dlls}. Please consider adding their paths to SEARCHDIRS when calling superbuild_package macro.")
endif()
endfunction()
\ No newline at end of file
......@@ -331,9 +331,11 @@ if(WIN32)
file(WRITE "${CMAKE_BINARY_DIR}/_mingw/CMakeLists.txt"
"cmake_minimum_required(VERSION 2.6)
include(CMakeParseArguments)
include(CMakeDetermineSystem)
set(Monteverdi_SOURCE_DIR \"${Monteverdi_SOURCE_DIR}\")
set(OTB_MODULES_DIR \"${OTB_MODULES_DIR}\")
set(QT_PLUGINS_DIR \"${QT_PLUGINS_DIR}\")
set(CMAKE_CROSSCOMPILING ON)
set(QT_TRANSLATIONS_DIR \"${QT_TRANSLATIONS_DIR}\")
set(Monteverdi_BINARY_DIR \"${CMAKE_BINARY_DIR}\")
set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")
......@@ -343,7 +345,7 @@ if(WIN32)
package_mingw(
ARCH \"${mxearch}\"
MXEROOT \"${mxeroot}\"
PREFIX_DIR \"${archive_name}\"
STAGE_DIR \"${archive_name}\"
SEARCHDIRS \"\")")
add_custom_target(InstallProject
......
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