From 75fddffc0859dd769a49f6a413008e4ebd15a37d Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 17 Jul 2019 10:08:12 +0300 Subject: [PATCH] Enable CMake-based build for Borland and Watcom compilers Issue #105 (bdwgc). * CMakeLists.txt [BORLAND] (add_compile_options): Specify /a4 and /w /w-pro /w-aus /w-par /w-ccc /w-inl /w-rch; add comment. * CMakeLists.txt [WATCOM] (add_compile_options): Specify /zp4 and /wx. * CMakeLists.txt [enable_werror && BORLAND] (add_compile_options): Specify /w!. * CMakeLists.txt [enable_werror && WATCOM] (add_compile_options): Specify /we. * CMakeLists.txt [!enable_single_obj_compilation && !BUILD_SHARED_LIBS && BORLAND] (add_compile_options): Specify /w-use; add comment. * CMakeLists.txt [build_tests && WATCOM] (gctest): Specify /wcd=13 /wcd=201 /wcd=367 /wcd=368 /wcd=726 target compile options; add comment. * doc/README.win32 (Watcom compiler): Mention that OpenWatcom 2.0 is tested on; remove note that cord is not ported; add note about the new way to build the collector using CMake script. --- CMakeLists.txt | 29 +++++++++++++++++++++++++++-- doc/README.win32 | 8 +++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fef247f..a8806602 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,14 +66,26 @@ if (APPLE AND ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")) CACHE STRING "Build architectures for Mac OS X" FORCE) endif() +# Set struct packing alignment to word (instead of 1-byte). +if (BORLAND) + add_compile_options(/a4) +elseif (WATCOM) + add_compile_options(/zp4) +endif() + # Output all warnings. -if (MSVC) +if (BORLAND) + # All warnings except for particular ones. + add_compile_options(/w /w-pro /w-aus /w-par /w-ccc /w-inl /w-rch) +elseif (MSVC) # All warnings but ignoring "unreferenced formal parameter" and # "conditional expression is constant" ones. add_compile_options(/W4 /wd4100 /wd4127) # Disable crt security warnings, since unfortunately they warn about all # sorts of safe uses of strncpy. add_definitions("-D_CRT_SECURE_NO_DEPRECATE") +elseif (WATCOM) + add_compile_options(/wx) else() # TODO add -[W]pedantic -Wno-long-long add_compile_options(-Wall -Wextra) @@ -252,8 +264,12 @@ if (enable_checksums) endif(enable_checksums) if (enable_werror) - if (MSVC) + if (BORLAND) + add_compile_options(/w!) + elseif (MSVC) add_compile_options(/WX) + elseif (WATCOM) + add_compile_options(/we) else() add_compile_options(-Werror) if (APPLE) @@ -269,6 +285,9 @@ if (enable_single_obj_compilation OR BUILD_SHARED_LIBS) add_definitions("-DGC_PTHREAD_START_STANDALONE") set(SRC ${SRC} pthread_start.c) endif(CMAKE_USE_PTHREADS_INIT) +elseif (BORLAND) + # Suppress "GC_push_contents_hdr() is declared but never used" warning. + add_compile_options(/w-use) endif() if (BUILD_SHARED_LIBS) @@ -367,6 +386,12 @@ if (build_tests) add_executable(gctest WIN32 tests/test.c) target_link_libraries(gctest PRIVATE gc) add_test(NAME gctest COMMAND gctest) + if (WATCOM) + # Suppress "conditional expression in if statement is always true/false" + # and "unreachable code" warnings in GC_MALLOC_[ATOMIC_]WORDS. + target_compile_options(gctest PRIVATE + /wcd=13 /wcd=201 /wcd=367 /wcd=368 /wcd=726) + endif() add_executable(hugetest tests/huge_test.c) target_link_libraries(hugetest PRIVATE gc) diff --git a/doc/README.win32 b/doc/README.win32 index 67b14763..f05fb9c6 100644 --- a/doc/README.win32 +++ b/doc/README.win32 @@ -106,7 +106,7 @@ Watcom compiler Ivan V. Demakov's README for the Watcom port: -The collector has been compiled with Watcom C 10.6 and 11.0. +The collector has been tested with Watcom C 10.6, 11.0 and OpenWatcom 2.0. It runs under win32, win32s, and even under msdos with dos4gw dos-extender. It should also run under OS/2, though this isn't tested. Under win32 the collector can be built either as dll @@ -118,8 +118,6 @@ attempt has been made) leads to broken executables. Incremental collection is supported (except for MSDOS and OS/2). -cord is not ported. - Before compiling you may need to edit WCC_MAKEFILE to set target platform, library type (dynamic or static), calling conventions, and optimization options. @@ -134,6 +132,10 @@ If the gc is compiled as dll, the macro "GC_DLL" should be defined before including "gc.h" (for example, with -DGC_DLL compiler option). It's important, otherwise resulting programs will not run. +The alternate way to compile the collector is to use cmake build system: + cmake -G "Watcom WMake" . + cmake --build . + Special note for OpenWatcom users: the C (unlike the C++) compiler (of the latest stable release, not sure for older ones) doesn't force pointer global variables (i.e. not struct fields, not sure for locals) to be aligned unless -- 2.40.0