1# Find the Cygwin DLL dependencies of dakota.exe that live in /bin or
2# /lib and install to ${CMAKE_INSTALL_PREFIX}/bin
3
4# NOTE: This script will only work for make install from top of build tree
5# TODO: Review string quoting conventions and test with spaces in filename
6
7# Function to install a single Dakota dll dependency
8# (used by multiple platforms)
9function(dakota_install_dll dakota_dll)
10  if (EXISTS "${dakota_dll}")
11    get_filename_component(dll_filename "${dakota_dll}" NAME)
12    message("-- Installing: ${CMAKE_INSTALL_PREFIX}/bin/${dll_filename}")
13    file(COPY "${dakota_dll}" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" FILE_PERMISSIONS
14      OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
15  else()
16    message(WARNING "Install couldn't find dynamic dependency ${dakota_dll}")
17  endif()
18endfunction()
19
20if ( DAKOTA_JENKINS_BUILD OR DEFINED ENV{WORKSPACE} )
21  # By convention, all Dakota, jenkins-driven build jobs use a 'build'
22  # subdir for clear separation of source and build trees in the WORKSPACE
23  set( CMAKE_CURRENT_BINARY_DIR $ENV{WORKSPACE}/build )
24elseif ( NOT CMAKE_CURRENT_BINARY_DIR )
25  # Assume build takes place in Cygwin, so use PWD, not CD
26  set( CMAKE_CURRENT_BINARY_DIR $ENV{PWD} )
27endif()
28
29# Get the DLLs only in cygwin\bin or cygwin\lib as a semicolon-separated list
30execute_process(
31  COMMAND cygcheck.exe "${CMAKE_CURRENT_BINARY_DIR}/src/dakota.exe"
32  COMMAND egrep "cygwin\\\\(bin|lib)\\\\"
33  COMMAND tr "\\n" ";"
34  OUTPUT_VARIABLE dakota_cygwin_dlls
35  )
36
37# Ignore empty list elements:
38cmake_policy(PUSH)
39cmake_policy(SET CMP0007 OLD)
40list(REMOVE_DUPLICATES dakota_cygwin_dlls)
41cmake_policy(POP)
42
43# Process each DLL and install
44foreach(dakota_dll ${dakota_cygwin_dlls})
45  # Get a Cygwin unix-style path
46  execute_process(
47    COMMAND cygpath.exe "${dakota_dll}"
48    OUTPUT_VARIABLE dakota_dll
49    )
50  # Remove leading and trailing whitespace, including newlines
51  string(STRIP "${dakota_dll}" dakota_dll)
52  dakota_install_dll("${dakota_dll}")
53endforeach()
54