Pārlūkot izejas kodu

OpenWatcom: Support CMAKE_WATCOM_RUNTIME_LIBRARY with Linux and OS/2 builds

Cameron Cawley 3 gadi atpakaļ
vecāks
revīzija
6a2b016bbd

+ 2 - 1
Help/policy/CMP0136.rst

@@ -22,7 +22,8 @@ out of the default :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` values and instead
 offer a first-class abstraction.  The :variable:`CMAKE_WATCOM_RUNTIME_LIBRARY`
 variable and :prop_tgt:`WATCOM_RUNTIME_LIBRARY` target property may be set to
 select the Watcom runtime library.  If they are not set then CMake uses the
-default value ``MultiThreadedDLL`` which is equivalent to the original flags.
+default value ``MultiThreadedDLL`` on Windows and ``SingleThreaded`` on other
+platforms, which is equivalent to the original flags.
 
 This policy provides compatibility with projects that have not been updated
 to be aware of the abstraction.  The policy setting takes effect as of the

+ 4 - 2
Help/prop_tgt/WATCOM_RUNTIME_LIBRARY-VALUES.txt

@@ -3,13 +3,15 @@
   statically-linked runtime library.
 ``SingleThreadedDLL``
   Compile with ``-br`` or equivalent flag(s) to use a single-threaded
-  dynamically-linked runtime library.
+  dynamically-linked runtime library. This is not available for Linux
+  targets.
 ``MultiThreaded``
   Compile with ``-bm`` or equivalent flag(s) to use a multi-threaded
   statically-linked runtime library.
 ``MultiThreadedDLL``
   Compile with ``-bm -br`` or equivalent flag(s) to use a multi-threaded
-  dynamically-linked runtime library.
+  dynamically-linked runtime library. This is not available for Linux
+  targets.
 
 The value is ignored on non-Watcom compilers but an unsupported value will
 be rejected as an error when using a compiler targeting the Watcom ABI.

+ 2 - 1
Help/prop_tgt/WATCOM_RUNTIME_LIBRARY.rst

@@ -24,7 +24,8 @@ selects for the target ``foo`` a multi-threaded statically-linked runtime
 library.
 
 If this property is not set then CMake uses the default value
-``MultiThreadedDLL`` to select a Watcom runtime library.
+``MultiThreadedDLL`` on Windows and ``SingleThreaded`` on other
+platforms to select a Watcom runtime library.
 
 .. note::
 

+ 2 - 2
Help/variable/CMAKE_WATCOM_RUNTIME_LIBRARY.rst

@@ -26,8 +26,8 @@ library.
 
 If this variable is not set then the :prop_tgt:`WATCOM_RUNTIME_LIBRARY` target
 property will not be set automatically.  If that property is not set then
-CMake uses the default value ``MultiThreadedDLL`` to select a Watcom runtime
-library.
+CMake uses the default value ``MultiThreadedDLL`` on Windows and
+``SingleThreaded`` on other platforms to select a Watcom runtime library.
 
 .. note::
 

+ 1 - 0
Modules/Platform/Linux-OpenWatcom-C.cmake

@@ -1 +1,2 @@
 include(Platform/Linux-OpenWatcom)
+__linux_open_watcom(C)

+ 1 - 0
Modules/Platform/Linux-OpenWatcom-CXX.cmake

@@ -1 +1,2 @@
 include(Platform/Linux-OpenWatcom)
+__linux_open_watcom(CXX)

+ 13 - 0
Modules/Platform/Linux-OpenWatcom.cmake

@@ -10,6 +10,14 @@ string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " system linux opt noextension")
 string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " system linux")
 string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " system linux")
 
+cmake_policy(GET CMP0136 __LINUX_WATCOM_CMP0136)
+if(__LINUX_WATCOM_CMP0136 STREQUAL "NEW")
+  set(CMAKE_WATCOM_RUNTIME_LIBRARY_DEFAULT "SingleThreaded")
+else()
+  set(CMAKE_WATCOM_RUNTIME_LIBRARY_DEFAULT "")
+endif()
+unset(__LINUX_WATCOM_CMP0136)
+
 # single/multi-threaded                 /-bm
 # default is setup for single-threaded libraries
 string(APPEND CMAKE_C_FLAGS_INIT " -bt=linux")
@@ -23,3 +31,8 @@ if(CMAKE_CROSSCOMPILING)
     set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/lh)
   endif()
 endif()
+
+macro(__linux_open_watcom lang)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_WATCOM_RUNTIME_LIBRARY_SingleThreaded         "")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_WATCOM_RUNTIME_LIBRARY_MultiThreaded          -bm)
+endmacro()

+ 1 - 0
Modules/Platform/OS2-OpenWatcom-C.cmake

@@ -1 +1,2 @@
 include(Platform/OS2-OpenWatcom)
+__os2_open_watcom(C)

+ 1 - 0
Modules/Platform/OS2-OpenWatcom-CXX.cmake

@@ -1 +1,2 @@
 include(Platform/OS2-OpenWatcom)
+__os2_open_watcom(CXX)

+ 15 - 0
Modules/Platform/OS2-OpenWatcom.cmake

@@ -16,6 +16,14 @@ endif()
 set(CMAKE_C_COMPILE_OPTIONS_DLL "-bd") # Note: This variable is a ';' separated list
 set(CMAKE_SHARED_LIBRARY_C_FLAGS "-bd") # ... while this is a space separated string.
 
+cmake_policy(GET CMP0136 __OS2_WATCOM_CMP0136)
+if(__OS2_WATCOM_CMP0136 STREQUAL "NEW")
+  set(CMAKE_WATCOM_RUNTIME_LIBRARY_DEFAULT "SingleThreaded")
+else()
+  set(CMAKE_WATCOM_RUNTIME_LIBRARY_DEFAULT "")
+endif()
+unset(__OS2_WATCOM_CMP0136)
+
 string(APPEND CMAKE_C_FLAGS_INIT " -bt=os2")
 string(APPEND CMAKE_CXX_FLAGS_INIT " -bt=os2 -xs")
 
@@ -33,3 +41,10 @@ if(NOT CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES)
     set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES $ENV{WATCOM}/h $ENV{WATCOM}/h/os2)
   endif()
 endif()
+
+macro(__os2_open_watcom lang)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_WATCOM_RUNTIME_LIBRARY_SingleThreaded         "")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_WATCOM_RUNTIME_LIBRARY_SingleThreadedDLL      -br)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_WATCOM_RUNTIME_LIBRARY_MultiThreaded          -bm)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_WATCOM_RUNTIME_LIBRARY_MultiThreadedDLL       -bm -br)
+endmacro()