Skip to content

Add MSVC build support and install rules to CMake build.#510

Open
manuelkNVDA wants to merge 1 commit into
berkeley-abc:masterfrom
manuelkNVDA:cmake-msvc-and-install
Open

Add MSVC build support and install rules to CMake build.#510
manuelkNVDA wants to merge 1 commit into
berkeley-abc:masterfrom
manuelkNVDA:cmake-msvc-and-install

Conversation

@manuelkNVDA
Copy link
Copy Markdown

@manuelkNVDA manuelkNVDA commented May 28, 2026

Summary

  • Adds a Visual Studio / MSVC build path alongside the existing Linux build.
  • Adds install rules and a CMake package config so downstream projects can find_package(abc) and link against abc::abc.

note to reviewers: diffing CMakeLists.txt in github's web tool is ugly, but the MSVC branch genuinely leaves the existing code path untouched ; using p4merge with white-space ignored is much more readable.

What's new

MSVC build branch in CMakeLists.txt (if(MSVC)):

  • Source list derived by parsing the per-module module.make files, matching the upstream Makefile's canonical
    source list (somewhat future-proof to future file additions, but relies on regex).
  • CRT macros (WIN32_NO_DLL, WIN32_LEAN_AND_MEAN, HAVE_STRUCT_TIMESPEC, PTW32_STATIC_LIB)
    configured for a static build with the in-tree pthreads-win32 shim.
  • Embedded debug info (CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "Embedded") to avoid PDB write
    contention with ~1370 parallel TUs.
  • UfarPthStub.c provides no-op pthread implementations so the unconditional pthread references in
    UfarPth.cpp link without a full pthreads library

Install rules and package config (applied to both MSVC and Linux):

  • <prefix>/bin/abc[.exe]
  • <prefix>/lib/libabc.{a,lib}
  • <prefix>/include/abc/<full src/ header tree>
  • <prefix>/lib/cmake/abc/{abcConfig,abcConfigVersion,abcTargets}*.cmake

Downstream usage:

project(my_tool LANGUAGES C CXX)

find_package(abc CONFIG REQUIRED)

target_link_libraries(my_tool PRIVATE abc::abc)

Related issues

Fixes #71cmake files don't contain any install instructions. Adds the missing install rules.

Fixes #56Shared library is installed w/out the headers. The full src/ header tree is installed under ${CMAKE_INSTALL_INCLUDEDIR}/abc/.
(The shared-library / SONAME part of that issue is outside this PR's scope: we still install the static libabc)

Related: #451Building DEB package for libabc-dev. This PR provides the install rules, exported targets, and abcConfig.cmake that a downstream DEB/CPack packager needs, but does not itself add CPack DEB rules, pkg-config generation, or a shared-library build. Those become small follow-ups on top of the infrastructure here.

Reworks the Visual Studio / MSVC build path while preserving the existing Linux
build. Adds install rules and a CMake package config so downstream projects can
`find_package(abc)` and link against `abc::abc`.

CMakeLists.txt:
 - Bumps cmake_minimum_required to 3.25 (for CMAKE_MSVC_DEBUG_INFORMATION_FORMAT
   and CMP0141) and moves `project(abc VERSION 1.0.0 ...)` to the top.
 - Adds an `if(MSVC) ... else() ...` split: the MSVC branch parses the
   per-module `module.make` files to derive the source list (matching
   what the upstream Makefile uses), configures CRT macros / warning
   suppressions / pthread shim defines, embeds debug info in each .obj
   to avoid PDB contention with ~1370 parallel TUs, and adds a
   UfarPthStub.c with no-op pthread implementations for the
   UfarPth.cpp symbols that are referenced unconditionally on Windows.
 - The non-MSVC `else()` branch is byte-identical to the previous
   top-level logic, with two minor changes:
     * `abc_properties` wraps the source-tree include in
       `$<BUILD_INTERFACE:...>` so it doesn't leak into the exported
       targets file at install time.
     * The redundant inner `project(abc)` is removed so the top-level
       project version survives.
 - Adds standardized install rules (applied to both branches):
     <prefix>/bin/abc[.exe]
     <prefix>/lib/lib{abc.a,abc.lib}
     <prefix>/include/abc/<full src/ header tree>
     <prefix>/lib/cmake/abc/{abcConfig,abcConfigVersion,abcTargets}*.cmake
   plus a `cmake/abcConfig.cmake.in` template for find_package(abc).

Source patches required for MSVC compilation:
 - src/misc/util/abc_global.h: guard the _CRTDBG_MAP_ALLOC block with
   !defined(__cplusplus) so the debug-heap macros don't substitute
   `free` inside C++ TUs (breaks CaDiCaL's util.hpp).
 - src/opt/eslim/utils.hpp: fix _BitScanForward64 call -- the first
   argument must be `unsigned long *`.
 - src/opt/eslim/windowMan.tpp: missing semicolon in the no-pthreads
   code path.
 - src/proof/cec/cecProve.c: move two pthread_t prototypes inside the
   existing `#ifdef ABC_USE_PTHREADS` guard.

.gitignore: remove `/cmake` entry because we need the cmake folder for
the added package-config template.

Verified end-to-end on MSVC 16 & 17 (Release + Debug) and Linux/WSL2
(Ubuntu, gcc 13.3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The project doesn't install anything Shared libary is installed w/out the headers

1 participant