Skip to content

Commit 45c9461

Browse files
committed
Open Watcom (DOS target) support
1 parent bc2ce96 commit 45c9461

File tree

5 files changed

+64
-16
lines changed

5 files changed

+64
-16
lines changed

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
66
set(CMAKE_C_STANDARD 90)
77

88
add_library("${PROJECT_NAME}_compiler_flags" INTERFACE)
9-
message(STATUS "MSVC_VERSION = ${MSVC_VERSION}")
10-
if (NOT DEFINED MSVC_VERSION OR MSVC_VERSION STRGREATER "1900") # 2015
9+
if (NOT DEFINED MSVC_VERSION
10+
OR MSVC_VERSION STRGREATER "1900" # 2015
11+
OR NOT (CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom"))
1112
target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_${CMAKE_C_STANDARD}")
12-
elseif (MSVC_VERSION STRLESS_EQUAL "1900" AND NOT EXISTS "${CMAKE_BINARY_DIR}/c89stringutils_export.h")
13+
elseif ((MSVC_VERSION STRLESS_EQUAL "1900"
14+
OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom"
15+
OR CYGWIN)
16+
AND NOT EXISTS "${CMAKE_BINARY_DIR}/c89stringutils_export.h")
1317
file(COPY "${CMAKE_SOURCE_DIR}/c89stringutils/c89stringutils_export_pregen.h"
1418
DESTINATION "${CMAKE_BINARY_DIR}")
1519
file(RENAME "${CMAKE_BINARY_DIR}/c89stringutils_export_pregen.h"

README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ c89stringutils
66
[![C89](https://img.shields.io/badge/C-89-blue)](https://en.wikipedia.org/wiki/C89_(C_version))
77

88
C89 is missing some nice things. As is MSVC.
9-
This adds the string related functionality for Windows (particularly: MSVC) and is tested additionally on: SunOS, Linux, BSD, and macOS.
9+
This adds the string related functionality for:
10+
- Windows
11+
- MSVC 2005
12+
- MSVC 2022 (should support all other versions also)
13+
- MinGW
14+
- Open Watcom 2.0 (including DOS target)
15+
- SunOS
16+
- Linux
17+
- BSD
18+
- macOS
1019

1120
Everything is hidden behind `ifdef`s so if the compiler/OS supports the function, that function will be used instead of the one provided by this library.
1221

13-
Header only (to simplify including). Just `#define C89STRINGUTILS_IMPLEMENTATION` once-only in your program (before including the header).
14-
1522
### String functions implemented
1623

1724
| Function | Citation |
@@ -29,16 +36,48 @@ Additionally `jasprintf`, a version of `asprintf` that concatenates on successiv
2936

3037
### Dependencies
3138

32-
- [CMake](https://cmake.org) (3.11 or later)
39+
- [CMake](https://cmake.org) (3.11 for MSVC 2005 or newer versions for other targets)
3340
- C compiler (any that work with CMake, and were released within the last 30 years)
3441

35-
### Build
42+
### Configure, build, and test
3643

3744
```bash
3845
mkdir build && cd build
3946
cmake ..
4047
cmake --build .
48+
ctest -C Debug
49+
```
50+
51+
#### Instructions for MSVC 2005
52+
53+
With cmake-3.11.4 specified, do:
54+
```sh
55+
mkdir build_msvc2005 && cd build_msvc2005
56+
cmake-3.11.4-win64-x64\bin\cmake -DCMAKE_WARN_VS8=OFF -DCMAKE_BUILD_TYPE="Debug" -G "Visual Studio 8 2005" ..
57+
cmake-3.11.4-win64-x64\bin\cmake --build .
58+
cmake-3.11.4-win64-x64\bin\ctest -C Debug
59+
```
60+
(the last two commands can be run by opening the solution in Visual Studio 2005)
61+
62+
Alternatively with newer versions of CMake (tested 3.26.3):
63+
```sh
64+
mkdir build_msvc_nmake2005 && cd build_msvc_nmake2005
65+
cmake -DCMAKE_BUILD_TYPE="Debug" -G "NMake Makefiles" ..
66+
cmake --build .
67+
ctest -C Debug
68+
```
69+
70+
#### Instructions for Open Watcom (DOS target)
71+
72+
With v2 from https://github.com/open-watcom/open-watcom-v2/releases installed:
73+
```sh
74+
WATCOM\owsetenv.bat
75+
mkdir build_dos && cd build_dos
76+
cmake -G "Watcom WMake" -D CMAKE_SYSTEM_NAME "DOS" -D CMAKE_SYSTEM_PROCESSOR "I86" ..
77+
cmake --build .
78+
ctest -C Debug
4179
```
80+
(that test phase might fail if you're running this on a non-DOS host)
4281

4382
---
4483

c89stringutils/c89stringutils_string_extras.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <stdio.h>
1111
#include <string.h>
1212

13-
#include "c89stringutils_export.h"
14-
1513
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
1614
defined(__bsdi__) || defined(__DragonFly__) || defined(BSD)
1715
#define ANY_BSD
@@ -42,6 +40,8 @@
4240

4341
#endif /* defined(_MSC_VER) && !defined(__INTEL_COMPILER) */
4442

43+
#elif defined(__WATCOMC__)
44+
4545
#else
4646

4747
#include <sys/param.h>
@@ -69,6 +69,13 @@
6969
#endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
7070
defined(__NT__) */
7171

72+
#if OLD_MSVC || defined(__WATCOMC__) || defined(__CYGWIN__)
73+
#ifdef C89STRINGUTILS_EXPORT
74+
#undef C89STRINGUTILS_EXPORT
75+
#endif /* C89STRINGUTILS_EXPORT */
76+
#define C89STRINGUTILS_EXPORT __declspec(dllimport)
77+
#endif
78+
7279
#if defined(__STDC_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__
7380

7481
#define HAVE_STRERRORLEN_S

c89stringutils_tests/test_c89stringutils/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ source_group("Source Files" FILES "${Source_Files}")
3131

3232
add_executable("${EXEC_NAME}" "${Header_Files}" "${Source_Files}")
3333

34-
target_link_libraries("${EXEC_NAME}" PRIVATE "c89stringutils_compiler_flags" "c89stringutils")
35-
34+
target_link_libraries("${EXEC_NAME}" PRIVATE "c89stringutils")
35+
if (NOT CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
36+
target_link_libraries("${EXEC_NAME}" PRIVATE "c89stringutils_compiler_flags" "c89stringutils")
37+
endif (NOT CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
3638
target_include_directories(
3739
"${EXEC_NAME}"
3840
PRIVATE

c89stringutils_tests/test_c89stringutils/test.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#ifdef _MSC_VER
2-
#endif /* _MSC_VER */
3-
#define _CRT_SECURE_NO_WARNINGS 1
4-
51
#include <greatest.h>
62

73
#include "test_string_extras.h"

0 commit comments

Comments
 (0)