Skip to content

Fix Windows build compatibility (MSVC cl.exe and clang-cl)#53

Open
lorisercole wants to merge 5 commits intowavefunction91:masterfrom
lorisercole:fix/msvc-build
Open

Fix Windows build compatibility (MSVC cl.exe and clang-cl)#53
lorisercole wants to merge 5 commits intowavefunction91:masterfrom
lorisercole:fix/msvc-build

Conversation

@lorisercole
Copy link
Copy Markdown

  • Add MSVC native cl.exe build support:
    • Remove dead exx_coeff static constexpr in deorbitalized.hpp that referenced non-existent kernel_traits members (MSVC eagerly instantiates; GCC/Clang defer since never ODR-used)
    • Replace C++ alternative operator tokens (not, and, or) with !, &&, || across headers and source files (MSVC cl.exe requires /permissive- otherwise)
    • Add _USE_MATH_DEFINES compile definition for M_PI
    • Suppress MSVC warnings (C4003, C4061, C4244, C4266, C4267, C4365, C4514, C4710, C4711, C4800, C4820, C5246)
    • Replace sed PATCH_COMMAND for libxc with portable CMake -P script so FetchContent works on Windows without Unix tools
  • Add clang-cl warning suppression flags (PUBLIC, to cover ExchCXX headers included by consumers)
  • Replace deprecated strdup with _strdup to fix MSVC C4996 warning

lorisercole and others added 5 commits April 27, 2026 20:22
- Remove dead `exx_coeff` static constexpr in `deorbitalized.hpp` that
  referenced non-existent members in kernel_traits (MSVC eagerly
  instantiates it; GCC/Clang deferred since it was never ODR-used)
- Replace C++ alternative operator tokens (`not`, `and`, `or`) with
  standard `!`, `&&`, `||` across headers and source files (MSVC cl.exe
  does not recognize them without /permissive-)
- Add `_USE_MATH_DEFINES` compile definition for MSVC (M_PI)
- Suppress MSVC warning C4800 (implicit double-to-bool conversion in
  auto-generated kernel code)
- Replace `sed` PATCH_COMMAND for libxc with portable CMake -P script
  so FetchContent works on Windows without Unix tools
Co-authored-by: Copilot <copilot@github.com>
warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets Windows toolchain compatibility (MSVC cl.exe and clang-cl) by removing MSVC-sensitive template instantiation triggers, avoiding alternative operator tokens, and making the libxc FetchContent patch step portable.

Changes:

  • Replaced not/and/or tokens with !/&&/|| in several translation units and headers.
  • Updated CMake to add MSVC/clang-cl-specific definitions and warning suppressions; replaced a sed-based libxc patch with a CMake -P script.
  • Removed a dead exx_coeff constexpr in deorbitalized.hpp and adjusted exception code to address MSVC deprecation warnings.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/xc_functional.cxx Replaces alternative operator tokens to improve MSVC compatibility.
src/libxc.cxx Replaces or with `
src/CMakeLists.txt Adds MSVC/clang-cl compile definitions and warning suppression flags.
src/builtin_interface.cxx Replaces or with `
include/exchcxx/xc_functional.hpp Replaces not/and with !/&& in sanity/type checks.
include/exchcxx/impl/builtin/kernels/screening_interface.hpp Replaces not in if constexpr to satisfy MSVC parsing/compat.
include/exchcxx/impl/builtin/kernels/deorbitalized.hpp Removes a dead constexpr that referenced non-existent traits members.
include/exchcxx/exceptions/exchcxx_exception.hpp Switches to _strdup and updates macro to avoid not.
CMakeLists.txt Replaces a sed PATCH_COMMAND with a portable CMake script invocation.
cmake/patch_libxc_work_mgga.cmake New CMake script to patch libxc sources without Unix tools.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 61 to 70
const char* what() const noexcept override {
std::stringstream ss;
ss << "EXCHCXX Exception (" << msg_prefix_ << ")" << std::endl
<< " File " << file_ << std::endl
<< " Line " << line_ << std::endl;

auto msg = ss.str();

return strdup( msg.c_str() );
return _strdup( msg.c_str() );
}
Comment thread src/CMakeLists.txt
/wd4267 # conversion from 'size_t' to 'type', possible loss of data
/wd4365 # conversion from 'type1' to 'type2', signed/unsigned mismatch
/wd4514 # unreferenced inline function has been removed
/wd4267 # conversion from 'size_t' to 'type', possible loss of data
Comment thread src/CMakeLists.txt
Comment on lines +19 to +49
if(MSVC)
target_compile_definitions( exchcxx PUBLIC _USE_MATH_DEFINES )
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # clang-cl
target_compile_options( exchcxx PUBLIC
-Wno-c++98-compat
-Wno-c++98-compat-local-type-template-args
-Wno-c++98-compat-pedantic
-Wno-deprecated-declarations
-Wno-exit-time-destructors
-Wno-extra-semi
-Wno-extra-semi-stmt
-Wno-float-conversion
-Wno-float-equal
-Wno-global-constructors
-Wno-inconsistent-missing-destructor-override
-Wno-missing-prototypes
-Wno-missing-variable-declarations
-Wno-old-style-cast
-Wno-pre-c++14-compat
-Wno-pre-c++17-compat
-Wno-reserved-macro-identifier
-Wno-sign-conversion
-Wno-suggest-destructor-override
-Wno-switch-enum
-Wno-undefined-func-template
-Wno-unsafe-buffer-usage
-Wno-unsafe-buffer-usage-in-libc-call
-Wno-unused-macros
-Wno-unused-parameter
-Wno-unused-variable
)
Comment on lines +11 to +13
file(READ "${_file}" _content)
string(REPLACE "p->info->family != XC_KINETIC" "p->info->kind != XC_KINETIC" _content "${_content}")
file(WRITE "${_file}" "${_content}")
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.

2 participants