Skip to content

Commit

Permalink
Fix MSVC Windows build
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Gheorghiu <[email protected]>
  • Loading branch information
vsoftco committed Jan 23, 2025
1 parent 6847ebe commit a3cec85
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ endif()

# Windows issues with Microsoft Visual Studio
if(MSVC)
add_definitions(-DNOMINMAX)
# MSVC lack of pthread.h
include_directories(SYSTEM libs/third_party/pthreadwin32)
add_compile_options(-bigobj)
add_compile_options(/bigobj)
add_compile_options(/utf-8)
if(MSVC_VERSION GREATER_EQUAL 1914)
add_compile_options("/Zc:__cplusplus")
endif()
Expand Down
8 changes: 8 additions & 0 deletions cmake/pystaq.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# LSP and CMake support for pystaq

if(MSVC)
add_definitions(-DNOMINMAX)
# MSVC lack of pthread.h
include_directories(SYSTEM ${STAQ_INSTALL_DIR}/third_party/pthreadwin32)
add_compile_options(/bigobj)
add_compile_options(/utf-8)
endif()

# pybind11
include_directories(SYSTEM ${PYBIND11_INCLUDE_DIRS})
target_include_directories(
Expand Down
10 changes: 4 additions & 6 deletions cmake/staq_msvc.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# MSVC lack of pthread.h
if(MSVC)
add_definitions(-DNOMINMAX)
# MSVC lack of pthread.h
include_directories(SYSTEM ${STAQ_INSTALL_DIR}/third_party/pthreadwin32)
endif()

# MSVC bigobj
if(MSVC)
add_compile_options(-bigobj)
add_compile_options(/bigobj)
add_compile_options(/utf-8)
endif()
5 changes: 4 additions & 1 deletion libs/third_party/easy/sat2/cardinality.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@

#pragma once

#include <algorithm>
#include <deque>
#include <vector>

namespace easy::sat2 {

Expand Down Expand Up @@ -158,8 +160,9 @@ inline void increase_totalizer(std::vector<std::vector<int>>& dest, int& sid,
std::shared_ptr<totalizer_tree>& t,
uint32_t rhs) {
uint32_t const kmin = std::min(rhs + 1, t->num_inputs);
if (kmin <= t->vars.size())
if (kmin <= t->vars.size()) {
return;
}

increase_totalizer(dest, sid, t->left, rhs);
increase_totalizer(dest, sid, t->right, rhs);
Expand Down
3 changes: 2 additions & 1 deletion libs/third_party/glucose/glucose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ static inline double Glucose::cpuTime(void) {
// for that
// Added by Vlad on Mar. 30, 2020, Windows compatibility
#if defined(_WIN32) && defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#include <windows.h>
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
struct timezone {
int tz_minuteswest; /* minutes W of Greenwich */
Expand Down Expand Up @@ -2111,7 +2112,7 @@ int GetTimeOfDay(struct timeval* tv, struct timezone* tz) {

return 0;
}
#endif // _WIN32 && MSC_VER
#endif // _WIN32 && _MSC_VER
// END added by Vlad on Mar. 30, 2020, Windows compatibility

static inline double Glucose::realTime() {
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _load_shared_obj(name):
and not sys.platform == "cygwin"
and not sys.platform == "msys"
):
(extra_compile_args.append("-DNOMINMAX"),)
extra_compile_args.append("-Ilibs/third_party/pthreadwin32")
extra_compile_args.append("/utf-8")

ext_modules = [
Pybind11Extension(
Expand Down
11 changes: 8 additions & 3 deletions unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ FetchContent_Declare(
GIT_TAG main
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
# For Windows: Prevent overriding the parent project's compiler/linker settings,
# and add bigobj option

# Windows issues with Microsoft Visual Studio

# Prevent overriding the parent project's compiler/linker settings, and add
# bigobj and utf-8 option
if(MSVC)
add_compile_options(-bigobj)
add_definitions(-DNOMINMAX)
add_compile_options(/bigobj)
add_compile_options(/utf-8)
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
Expand Down

0 comments on commit a3cec85

Please sign in to comment.