From 80769cdd1e568c1dbc66651557d98bba0f70ea00 Mon Sep 17 00:00:00 2001
From: David Cole <david.cole@kitware.com>
Date: Fri, 29 Jul 2011 13:28:54 -0400
Subject: Add Watcom support to InstallRequiredSystemLibraries (#11866)

Also adds code to determine the version of the Watcom compiler
in use.

Thanks to J Decker for the patch.
---
 Modules/CMakeTestWatcomVersion.c             |  1 +
 Modules/InstallRequiredSystemLibraries.cmake | 34 +++++++++++++++++++++++++
 Modules/Platform/Windows-wcl386.cmake        | 38 ++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 Modules/CMakeTestWatcomVersion.c

diff --git a/Modules/CMakeTestWatcomVersion.c b/Modules/CMakeTestWatcomVersion.c
new file mode 100644
index 0000000..0343fb1
--- /dev/null
+++ b/Modules/CMakeTestWatcomVersion.c
@@ -0,0 +1 @@
+VERSION=__WATCOMC__
diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake
index 59e5ec1..b6735c1 100644
--- a/Modules/InstallRequiredSystemLibraries.cmake
+++ b/Modules/InstallRequiredSystemLibraries.cmake
@@ -330,6 +330,40 @@ IF(MSVC)
   ENDFOREACH(lib)
 ENDIF(MSVC)
 
+IF(WATCOM)
+  GET_FILENAME_COMPONENT( CompilerPath ${CMAKE_C_COMPILER} PATH )
+  IF(WATCOM17)
+     SET( __install__libs ${CompilerPath}/clbr17.dll
+       ${CompilerPath}/mt7r17.dll ${CompilerPath}/plbr17.dll )
+  ENDIF()
+  IF(WATCOM18)
+     SET( __install__libs ${CompilerPath}/clbr18.dll
+       ${CompilerPath}/mt7r18.dll ${CompilerPath}/plbr18.dll )
+  ENDIF()
+  IF(WATCOM19)
+     SET( __install__libs ${CompilerPath}/clbr19.dll
+       ${CompilerPath}/mt7r19.dll ${CompilerPath}/plbr19.dll )
+  ENDIF()
+  FOREACH(lib
+      ${__install__libs}
+      )
+    IF(EXISTS ${lib})
+      SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS
+        ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} ${lib})
+    ELSE()
+      IF(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
+        MESSAGE(WARNING "system runtime library file does not exist: '${lib}'")
+        # This warning indicates an incomplete Watcom installation
+        # or a bug somewhere above here in this file.
+        # If you would like to avoid this warning, fix the real problem, or
+        # set CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS before including
+        # this file.
+      ENDIF()
+    ENDIF()
+  ENDFOREACH()
+ENDIF()
+
+
 # Include system runtime libraries in the installation if any are
 # specified by CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS.
 IF(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
diff --git a/Modules/Platform/Windows-wcl386.cmake b/Modules/Platform/Windows-wcl386.cmake
index e96ebb5..c10fd78 100644
--- a/Modules/Platform/Windows-wcl386.cmake
+++ b/Modules/Platform/Windows-wcl386.cmake
@@ -81,3 +81,41 @@ SET(CMAKE_CXX_CREATE_STATIC_LIBRARY  "wlib ${CMAKE_LIB_QUIET} -n -b '<TARGET_UNQ
 
 # create a C static library
 SET(CMAKE_C_CREATE_STATIC_LIBRARY ${CMAKE_CXX_CREATE_STATIC_LIBRARY})
+
+IF(NOT CMAKE_WATCOM_COMPILER_TESTS_RUN)
+  SET(CMAKE_WATCOM_COMPILER_TESTS_RUN 1)
+  SET(testWatcomVersionFile
+    "${CMAKE_ROOT}/Modules/CMakeTestWatcomVersion.c")
+  STRING(REGEX REPLACE "/" "\\\\" testWatcomVersionFile "${testWatcomVersionFile}")
+  MESSAGE(STATUS "Check for Watcom compiler version")
+  SET(CMAKE_TEST_COMPILER ${CMAKE_C_COMPILER})
+  IF (NOT CMAKE_C_COMPILER)
+    SET(CMAKE_TEST_COMPILER ${CMAKE_CXX_COMPILER})
+  ENDIF()
+  EXECUTE_PROCESS(COMMAND ${CMAKE_TEST_COMPILER}
+    -q -pc \"${testWatcomVersionFile}\"
+    OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT
+    RETURN_VALUE CMAKE_COMPILER_RETURN
+    )
+  STRING(REGEX REPLACE "\n" " " compilerVersion "${CMAKE_COMPILER_OUTPUT}")
+  STRING(REGEX REPLACE ".*VERSION=(.*)" "\\1"
+    compilerVersion "${compilerVersion}")
+  IF(NOT CMAKE_COMPILER_RETURN)
+    SET(WATCOM16)
+    SET(WATCOM17)
+    SET(WATCOM18)
+    SET(WATCOM19)
+    IF("${compilerVersion}" LESS 1270)
+      SET(WATCOM16 1)
+    ENDIF()
+    IF("${compilerVersion}" EQUAL 1270)
+      SET(WATCOM17 1)
+    ENDIF()
+    IF("${compilerVersion}" EQUAL 1280)
+      SET(WATCOM18 1)
+    ENDIF()
+    IF("${compilerVersion}" EQUAL 1290)
+      SET(WATCOM19 1)
+    ENDIF()
+  ENDIF()
+ENDIF()
-- 
cgit v0.12


From ff5971635170af8754edb029b5345e17fb4de4fa Mon Sep 17 00:00:00 2001
From: David Cole <david.cole@kitware.com>
Date: Mon, 1 Aug 2011 15:29:13 -0400
Subject: Watcom: Use correct args for execute_process call (#11866)

I botched an exec_program to execute_process translation on Friday.
RESULT_VARIABLE is the correct argument to execute_process.
---
 Modules/Platform/Windows-wcl386.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Modules/Platform/Windows-wcl386.cmake b/Modules/Platform/Windows-wcl386.cmake
index c10fd78..3f8d65a 100644
--- a/Modules/Platform/Windows-wcl386.cmake
+++ b/Modules/Platform/Windows-wcl386.cmake
@@ -95,12 +95,12 @@ IF(NOT CMAKE_WATCOM_COMPILER_TESTS_RUN)
   EXECUTE_PROCESS(COMMAND ${CMAKE_TEST_COMPILER}
     -q -pc \"${testWatcomVersionFile}\"
     OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT
-    RETURN_VALUE CMAKE_COMPILER_RETURN
+    RESULT_VARIABLE CMAKE_COMPILER_RETURN
     )
   STRING(REGEX REPLACE "\n" " " compilerVersion "${CMAKE_COMPILER_OUTPUT}")
   STRING(REGEX REPLACE ".*VERSION=(.*)" "\\1"
     compilerVersion "${compilerVersion}")
-  IF(NOT CMAKE_COMPILER_RETURN)
+  IF("${CMAKE_COMPILER_RETURN}" STREQUAL "0")
     SET(WATCOM16)
     SET(WATCOM17)
     SET(WATCOM18)
-- 
cgit v0.12