From 317be26eee73f466b70dea1e848307995ac9a332 Mon Sep 17 00:00:00 2001 From: Andreas Schenk <andreas_schenk@hms.harvard.edu> Date: Fri, 21 Sep 2012 18:11:16 -0400 Subject: [PATCH] added dependency determination, copying and verification for windows --- cmake_support/CopyDependencies.cmake | 126 +++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 18 deletions(-) diff --git a/cmake_support/CopyDependencies.cmake b/cmake_support/CopyDependencies.cmake index ae48aaa88..f1bd03677 100644 --- a/cmake_support/CopyDependencies.cmake +++ b/cmake_support/CopyDependencies.cmake @@ -240,7 +240,9 @@ function(resolve_item context item exepath resolved_item_var) string(REPLACE "@loader_path" "${contextpath}" resolved_item "${resolved_item}") endif(resolved_item MATCHES "@loader_path") - get_filename_component(resolved_item "${resolved_item}" REALPATH) + if(NOT WIN32) + get_filename_component(resolved_item "${resolved_item}" REALPATH) + endif(NOT WIN32) if(IS_ABSOLUTE "${resolved_item}" AND EXISTS "${resolved_item}") set(${resolved_item_var} "${resolved_item}" PARENT_SCOPE) @@ -248,12 +250,14 @@ function(resolve_item context item exepath resolved_item_var) endif(IS_ABSOLUTE "${resolved_item}" AND EXISTS "${resolved_item}") set(ri "ri-NOTFOUND") - find_file(ri "${item}" ${exepath} NO_DEFAULT_PATH) - find_file(ri "${item}" ${exepath} /usr/lib) - if(WIN32 AND NOT UNIX) + if(UNIX AND NOT WIN32) + find_file(ri "${item}" ${exepath} NO_DEFAULT_PATH) + find_file(ri "${item}" ${exepath} /usr/lib) + else(UNIX AND NOT WIN32) find_program(ri "${item}" PATHS "${exepath}" NO_DEFAULT_PATH) + find_program(ri "${item}" PATHS "${CMAKE_INSTALL_PREFIX}/bin" NO_DEFAULT_PATH) find_program(ri "${item}" PATHS "${exepath}") - endif(WIN32 AND NOT UNIX) + endif(UNIX AND NOT WIN32) if(ri) set(resolved_item "${ri}") set(ri "ri-NOTFOUND") @@ -277,7 +281,11 @@ function(resolve_embedded_item item resolved_item_var) else(${item} MATCHES ${CMAKE_INSTALL_PREFIX}) # only embed libraries, therefore put into lib dir get_filename_component(item_name "${item}" NAME) - set(${resolved_item_var} "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/${item_name}" PARENT_SCOPE) + if(WIN32 AND NOT UNIX) + set(${resolved_item_var} "${CMAKE_INSTALL_PREFIX}/bin/${item_name}" PARENT_SCOPE) + else(WIN32 AND NOT UNIX) + set(${resolved_item_var} "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/${item_name}" PARENT_SCOPE) + endif(WIN32 AND NOT UNIX) endif(${item} MATCHES ${CMAKE_INSTALL_PREFIX}) endfunction(resolve_embedded_item) @@ -333,17 +341,19 @@ endfunction(change_install_names_for_item) #============================================================================= function(verify keys_var) foreach(key ${${keys_var}}) - get_dependencies_for_item("${${key}_RESOLVED_EMBEDDED_ITEM}" dependencies) - get_filename_component(exepath ${${key}_RESOLVED_EMBEDDED_ITEM} PATH) - foreach(dep ${dependencies}) - resolve_item( ${${key}_RESOLVED_EMBEDDED_ITEM} ${dep} exepath resolved_dep) - is_system_lib(${resolved_dep} system_flag) - if(NOT ${system_flag}) - if(NOT ${resolved_dep} MATCHES ${CMAKE_INSTALL_PREFIX}) - MESSAGE("Warning: item:'${${key}_RESOLVED_EMBEDDED_ITEM}' contains external dependency:'${resolved_dep}'") - endif(NOT ${resolved_dep} MATCHES ${CMAKE_INSTALL_PREFIX}) - endif(NOT ${system_flag}) - endforeach(dep) + if(NOT ${${key}_SYSTEMFLAG}) + get_dependencies_for_item("${${key}_RESOLVED_EMBEDDED_ITEM}" dependencies) + get_filename_component(exepath ${${key}_RESOLVED_EMBEDDED_ITEM} PATH) + foreach(dep ${dependencies}) + resolve_item( ${${key}_RESOLVED_EMBEDDED_ITEM} ${dep} exepath resolved_dep) + is_system_lib(${resolved_dep} system_flag) + if(NOT ${system_flag}) + if(NOT ${resolved_dep} MATCHES ${CMAKE_INSTALL_PREFIX}) + MESSAGE("Warning: item:'${${key}_RESOLVED_EMBEDDED_ITEM}' contains external dependency:'${resolved_dep}'") + endif(NOT ${resolved_dep} MATCHES ${CMAKE_INSTALL_PREFIX}) + endif(NOT ${system_flag}) + endforeach(dep) + endif(NOT ${${key}_SYSTEMFLAG}) endforeach(key) endfunction(verify) @@ -649,6 +659,28 @@ function(copy_resolved_item resolved_item resolved_embedded_item) endfunction(copy_resolved_item) +#============================================================================= +# function copy_python (OSX) +#============================================================================= +function(copy_python include_path version new_binary_path) + + + get_filename_component(real_python_include_path ${include_path} REALPATH) + get_filename_component(python_root_dir ${real_python_include_path}/../.. REALPATH) + file(COPY ${python_root_dir}/${LIB_DIR}/python${version}/ DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/python${version}) + file(GLOB py_config_files "${include_path}/pyconfig*.h") + file(COPY ${py_config_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/python${version}) + file(GLOB_RECURSE python_so_files "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/python${version}/*.so") + foreach(so_file ${python_so_files}) + file(RPATH_REMOVE FILE "${so_file}") + endforeach(so_file) + read_config(ost_config) + file(COPY ${python_root_dir}/Resources/Python.app/Contents/MacOS/Python DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + set(${new_binary_path} "${CMAKE_INSTALL_PREFIX}/bin/Python" PARENT_SCOPE) + string(REGEX REPLACE "pyexec=\"[^\n\$]*\"" "pyexec=\"\$DNG_BINDIR/Python\"\nexport PYTHONHOME=\$DNG_ROOT" ost_config "${ost_config}") + write_config("${ost_config}") +endfunction(copy_python) + elseif(WIN32 AND NOT UNIX) @@ -675,8 +707,10 @@ function(get_dependencies_for_item item list_var) endif(NOT dumpbin_cmd) set(ENV{VS_UNICODE_OUTPUT} "") # Block extra output from inside VS IDE. - execute_process( COMMAND ${dumpbin_cmd} /dependents ${item} OUTPUT_VARIABLE dumpbin_cmd_ov RESULT_VARIABLE retcode) + execute_process( COMMAND ${dumpbin_cmd} /dependents ${item} OUTPUT_VARIABLE dumpbin_cmd_ov ERROR_VARIABLE dumpbin_cmd_ev RESULT_VARIABLE retcode) if(retcode) + MESSAGE( "dumpbin output: '${dumpbin_cmd_ov}'") + MESSAGE( "dumpbin error output: '${dumpbin_cmd_ev}'") MESSAGE(FATAL_ERROR "dumpbin stopped with return code: '${retcode}'") endif(retcode) # Convert to a list of lines: @@ -693,6 +727,7 @@ function(get_dependencies_for_item item list_var) string(REGEX REPLACE "${dumpbin_regex}" "\\1" dep "${candidate}") list(APPEND dep_list ${dep}) endif("${candidate}" MATCHES "${dumpbin_regex}") + endforeach(candidate) set(${list_var} ${dep_list} PARENT_SCOPE) endfunction(get_dependencies_for_item) @@ -736,6 +771,32 @@ function(copy_resolved_item resolved_item resolved_embedded_item) endfunction(copy_resolved_item) +#============================================================================= +# function copy_python (Windows) +#============================================================================= +function(copy_python include_path version new_binary_path) + get_filename_component(real_python_include_path ${include_path} REALPATH) + get_filename_component(python_root_dir ${real_python_include_path}/.. REALPATH) + file(GLOB lib_files "${python_root_dir}/Lib/*") + file(COPY ${lib_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/python${version}) + file(GLOB py_config_files "${include_path}/pyconfig*.h") + file(COPY ${py_config_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/python${version}) + file(COPY ${python_root_dir}/python.exe DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + set(${new_binary_path} "${CMAKE_INSTALL_PREFIX}/bin/python.exe" PARENT_SCOPE) +endfunction(copy_python) + +#============================================================================= +# function copy_qt (Windows) +#============================================================================= +function(copy_qt library_dir plugin_dir plugins) + file(COPY ${plugin_dir} + DESTINATION ${CMAKE_INSTALL_PREFIX}/libexec/openstructure) + file(GLOB_RECURSE QT_PLUGINS "${CMAKE_INSTALL_PREFIX}/libexec/openstructure/*.dll") + set(${plugins} ${QT_PLUGINS} PARENT_SCOPE) + file(WRITE "${CMAKE_INSTALL_PREFIX}/libexec/openstructure/qt.conf" "[Paths]\nPlugins=../plugins\n") +endfunction(copy_qt) + + elseif(UNIX) @@ -877,6 +938,35 @@ function(copy_resolved_item resolved_item resolved_embedded_item) endfunction(copy_resolved_item) +#============================================================================= +# function copy_python (Linux) +#============================================================================= +function(copy_python include_path version new_binary_path) + + + get_filename_component(real_python_include_path ${include_path} REALPATH) + get_filename_component(python_root_dir ${real_python_include_path}/../.. REALPATH) + file(COPY ${python_root_dir}/${LIB_DIR}/python${version}/ DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/python${version}) + file(GLOB py_config_files "${include_path}/pyconfig*.h") + file(COPY ${py_config_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/python${version}) + file(GLOB_RECURSE python_so_files "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}/python${version}/*.so") + foreach(so_file ${python_so_files}) + file(RPATH_REMOVE FILE "${so_file}") + endforeach(so_file) + read_config(ost_config) + file(GLOB python_libs "${python_root_dir}/${LIB_DIR}/libpython${version}.so*") + file(COPY ${python_libs} DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIB_DIR}) + file(COPY ${python_root_dir}/bin/python${version} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + set(${new_binary_path} "${CMAKE_INSTALL_PREFIX}/bin/python${version}" PARENT_SCOPE) + string(REGEX REPLACE "pyexec=\"[^\n\$]*\"" "pyexec=\"\$DNG_BINDIR/python${version}\"\nexport PYTHONHOME=\$DNG_ROOT" ost_config "${ost_config}") + write_config("${ost_config}") +endfunction(copy_python) + + + +else(APPLE) + MESSAGE("Unknown platform, deployment will not work.") +endif(APPLE) -- GitLab