Skip to content

OW tools usage with VSCode

Bradley Bell edited this page Jun 25, 2024 · 6 revisions

Instructions for adding OW DOS targets to VSCode

Prerequisites:

Install Open Watcom V2 with DOS target operating system and environment variables. Install Visual Studio Code with C/C++, CMake, and CMake Tools extensions.

Configuration:

Launch VSCode and add Open Watcom CMake Kits:

Ctrl+Shift+P> CMake: Edit User-Local CMake Kits Add Open Watcom kits to cmake-tools-kits.json

{
    "name": "OpenWatcom v2 Beta (32-bit DOS)",
    "compilers": {
        "C": "C:\\WATCOM\\binnt64\\wcl386.exe",
        "CXX": "C:\\WATCOM\\binnt64\\wcl386.exe"
    },
    "preferredGenerator": {
        "name": "Watcom WMake"
    },
    "cmakeSettings": {
        "CMAKE_SYSTEM_NAME":"DOS"
    },
},
{
    "name": "OpenWatcom v2 Beta (16-bit DOS)",
    "compilers": {
        "C": "C:\\WATCOM\\binnt64\\wcl.exe",
        "CXX": "C:\\WATCOM\\binnt64\\wcl.exe"
    },
    "preferredGenerator": {
        "name": "Watcom WMake"
    },
    "cmakeSettings": {
        "CMAKE_SYSTEM_NAME":"DOS",
        "CMAKE_SYSTEM_PROCESSOR": "I86"
    }
} 

Create a folder (a workspace) and open it in VS Code. A popup will appear asking Do you trust the authors of the files in this folder? Click Yes, I trust the authors. Ctrl+Shift+P CMake: Quick Start Select Kit OpenWatcom v2 Beta (32-bit DOS) Enter a name for the project, press enter, then click on Select Executable. This will create a CMakeLists.txt and a main.cpp file.

Ctrl+Shift+P> Preferences: Open Workspace Settings (JSON) Add open watcom setting overrides to workspace .vscode/settings.json

{ 
     "cmake.configureArgs": [
         "-DCMAKE_CXX_COMPILER_WORKS=1",
         "-DCMAKE_C_COMPILER_WORKS=1"
    ],
    "cmake.generator": "Watcom WMake", //Comment this if you aren't using OpenWatcom compiler.
    "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
} 

Ctrl+Shift+P> C/C++ Edit Configurations (JSON) Add open watcom configuration overrides to workspace .vscode/c_cpp_properties.json

{
    "configurations": [
        {
            "name": "DOS32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/watcom/h/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "__WATCOMC__"
            ],
            "cStandard": "c89",
            "cppStandard": "c++98",
            "intelliSenseMode": "msvc-x86",
            "configurationProvider": "ms-vscode.cmake-tools",
            "compilerPath": "C:\\WATCOM\\binnt64\\wcl386.exe"
        }

Restart VSCode to load the configuration changes.

Upon restart, A popup message will ask would you like to configure project, select yes. This will create the build configuration. You can now build the executable.

Useful VSCode (Ctrl+Shift+P) commands:

CMake: Edit User-Local CMake Kits
CMake: Quick Start
Preferences: Open Workspace Settings (JSON)
C/C++: Edit Configurations (JSON)
CMake: Reset CMake Tools Extension State
CMake: Delete Cache and Reconfigure 

Example CMakeLists.txt

cmake_minimum_required(VERSION 3.18)
project(ex22 VERSION 0.1.0)

if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") 
    add_compile_options(-wcd=202 -wcd=201 -bt=dos4g -5s -s -d2 -zq -fr=nul)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -za99")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ze")
endif()

include(CTest)
enable_testing()

add_executable(ex22 dbg.h ex22.h ex22.c ex22_main.c)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Clone this wiki locally