You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GNUtoMS.cmake 4.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #=============================================================================
  2. # GNUtoMS - CMake module for Windows import library conversion
  3. # Copyright 2010-2011 Kitware, Inc.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. #
  13. # * Redistributions in binary form must reproduce the above copyright
  14. # notice, this list of conditions and the following disclaimer in the
  15. # documentation and/or other materials provided with the distribution.
  16. #
  17. # * Neither the name of Kitware, Inc. nor the names of its
  18. # contributors may be used to endorse or promote products derived
  19. # from this software without specific prior written permission.
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. #=============================================================================
  33. # GNUtoMS works only for the GNU toolchain on Windows (MinGW and MSys).
  34. set(GNUtoMS 0)
  35. if(NOT "${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU" OR NOT WIN32 OR CYGWIN)
  36. return()
  37. endif()
  38. # Locate auxiliary GNUtoMS files.
  39. get_filename_component(GNUtoMS_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
  40. set(GNUtoMS_DIR ${GNUtoMS_DIR}/GNUtoMS)
  41. if(NOT CMAKE_SIZEOF_VOID_P)
  42. enable_language(C) # Find CMAKE_SIZEOF_VOID_P reliably.
  43. endif()
  44. # Find MS development environment setup script for this architecture.
  45. if("${CMAKE_SIZEOF_VOID_P}" EQUAL 4)
  46. find_program(VCVARS32 NAMES vcvars32.bat
  47. PATHS
  48. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0\\Setup\\VC;ProductDir]/bin"
  49. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VC;ProductDir]/bin"
  50. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup\\VC;ProductDir]/bin"
  51. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1\\Setup\\VC;ProductDir]/bin"
  52. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++;ProductDir]/bin"
  53. )
  54. set(GNUtoMS_ENV "${VCVARS32}")
  55. set(GNUtoMS_ARCH x86)
  56. elseif("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
  57. find_program(VCVARSAMD64 NAMES vcvarsamd64.bat
  58. PATHS
  59. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0\\Setup\\VC;ProductDir]/bin/amd64"
  60. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VC;ProductDir]/bin/amd64"
  61. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup\\VC;ProductDir]/bin/amd64"
  62. )
  63. set(GNUtoMS_ENV "${VCVARSAMD64}")
  64. set(GNUtoMS_ARCH amd64)
  65. endif()
  66. if(GNUtoMS_ENV)
  67. set(GNUtoMS 1)
  68. # Create helper script to run lib.exe from MS environment.
  69. string(REPLACE "/" "\\" GNUtoMS_BAT "${GNUtoMS_ENV}")
  70. set(LIB ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/GNUtoMSlib.bat)
  71. configure_file(${GNUtoMS_DIR}/lib.bat.in ${LIB})
  72. # Teach CMake how to create a MS import library at link time.
  73. set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
  74. "${CMAKE_Fortran_CREATE_SHARED_LIBRARY} -Wl,--output-def,<TARGET_NAME>.def"
  75. "<CMAKE_COMMAND> -Dlib=\"${LIB}\" -Ddef=\"<TARGET_NAME>.def\" -Ddll=\"<TARGET>\" -Dimp=\"<TARGET_IMPLIB>\" -P \"${GNUtoMS_DIR}/lib.cmake\""
  76. )
  77. endif()