Skip to content

Commit 44a402b

Browse files
committed
Don't set /O2 unconditionally on Windows
When MSVC is being used and the build is a debug build, we get errors involving /O2 and /RCT1.
1 parent 650376e commit 44a402b

8 files changed

Lines changed: 49 additions & 23 deletions

File tree

pybind_interface/avx2/CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
cmake_minimum_required(VERSION 3.28)
1616
project(qsim)
1717

18-
IF (WIN32)
19-
add_compile_options(/arch:AVX2 /O2 /openmp)
20-
ELSE()
18+
if(WIN32)
19+
add_compile_options(/arch:AVX2 /openmp)
20+
# Only apply /O2 if the configuration is RELEASE.
21+
# This prevents a conflict with /RTC1 in DEBUG builds.
22+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
23+
else()
2124
add_compile_options(-mavx2 -mfma -O3 -flto=auto)
22-
ENDIF()
25+
endif()
2326

2427
if(APPLE)
2528
include_directories(
@@ -36,7 +39,7 @@ if(APPLE)
3639
)
3740
endif()
3841

39-
INCLUDE(../GetPybind11.cmake)
42+
include(../GetPybind11.cmake)
4043
pybind11_add_module(qsim_avx2 pybind_main_avx2.cpp)
4144

4245
target_link_libraries(qsim_avx2 PUBLIC OpenMP::OpenMP_CXX)

pybind_interface/avx512/CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
cmake_minimum_required(VERSION 3.28)
1616
project(qsim)
1717

18-
IF (WIN32)
19-
add_compile_options(/arch:AVX512 /O2 /openmp)
20-
ELSE()
18+
if(WIN32)
19+
add_compile_options(/arch:AVX512 /openmp)
20+
# Only apply /O2 if the configuration is RELEASE.
21+
# This prevents a conflict with /RTC1 in DEBUG builds.
22+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
23+
else()
2124
add_compile_options(-mavx512f -mbmi2 -O3 -flto=auto)
22-
ENDIF()
25+
endif()
2326

2427
if(APPLE)
2528
include_directories(
@@ -36,7 +39,7 @@ if(APPLE)
3639
)
3740
endif()
3841

39-
INCLUDE(../GetPybind11.cmake)
42+
include(../GetPybind11.cmake)
4043
pybind11_add_module(qsim_avx512 pybind_main_avx512.cpp)
4144

4245
target_link_libraries(qsim_avx512 PUBLIC OpenMP::OpenMP_CXX)

pybind_interface/basic/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ cmake_minimum_required(VERSION 3.28)
1616
project(qsim)
1717

1818
if(WIN32)
19-
add_compile_options(/O2 /openmp)
19+
add_compile_options(/openmp)
20+
# Only apply /O2 if the configuration is RELEASE.
21+
# This prevents a conflict with /RTC1 in DEBUG builds.
22+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
2023
else()
2124
add_compile_options(-O3 -flto=auto)
2225
endif()
@@ -36,7 +39,7 @@ if(APPLE)
3639
)
3740
endif()
3841

39-
INCLUDE(../GetPybind11.cmake)
42+
include(../GetPybind11.cmake)
4043
pybind11_add_module(qsim_basic pybind_main_basic.cpp)
4144

4245
target_link_libraries(qsim_basic PUBLIC OpenMP::OpenMP_CXX)

pybind_interface/cuda/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ cmake_minimum_required(VERSION 3.28)
1616
project(qsim LANGUAGES CXX CUDA)
1717

1818
if(WIN32)
19-
add_compile_options(/O2 /openmp)
19+
# Always apply AVX2 and openmp on Windows
20+
add_compile_options(/openmp)
21+
22+
# Only apply /O2 if the configuration is RELEASE.
23+
# This prevents a conflict with /RTC1 in DEBUG builds.
24+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
2025
else()
2126
add_compile_options(-O3 -flto=auto)
2227
endif()

pybind_interface/custatevec/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ cmake_minimum_required(VERSION 3.28)
1616
project(qsim LANGUAGES CXX CUDA)
1717

1818
if(WIN32)
19-
add_compile_options(/O2 /openmp)
19+
add_compile_options(/openmp)
20+
# Only apply /O2 if the configuration is RELEASE.
21+
# This prevents a conflict with /RTC1 in DEBUG builds.
22+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
2023
else()
2124
add_compile_options(-O3 -flto=auto)
2225
endif()
@@ -36,7 +39,7 @@ if(APPLE)
3639
)
3740
endif()
3841

39-
INCLUDE(../GetPybind11.cmake)
42+
include(../GetPybind11.cmake)
4043
find_package(Python3 3.10 REQUIRED)
4144

4245
include_directories(${pybind11_INCLUDE_DIRS})

pybind_interface/decide/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ include(CheckLanguage)
1919
check_language(CUDA)
2020

2121
if(WIN32)
22-
add_compile_options(/O2 /openmp)
22+
add_compile_options(/openmp)
23+
# Only apply /O2 if the configuration is RELEASE.
24+
# This prevents a conflict with /RTC1 in DEBUG builds.
25+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
2326
else()
2427
add_compile_options(-O3 -flto=auto)
2528
endif()

pybind_interface/hip/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ cmake_minimum_required(VERSION 3.28)
1616
project(qsim LANGUAGES CXX HIP)
1717

1818
if(WIN32)
19-
add_compile_options(/O2 /openmp)
19+
add_compile_options(/openmp)
20+
# Only apply /O2 if the configuration is RELEASE.
21+
# This prevents a conflict with /RTC1 in DEBUG builds.
22+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
2023
else()
2124
add_compile_options(-O3 -flto=auto)
2225
endif()
2326

24-
INCLUDE(../GetPybind11.cmake)
27+
include(../GetPybind11.cmake)
2528
find_package(PythonLibs 3.10 REQUIRED)
2629

2730
list(APPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake/hip")

pybind_interface/sse/CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
cmake_minimum_required(VERSION 3.28)
1616
project(qsim)
1717

18-
IF (WIN32)
19-
add_compile_options(/O2 /openmp)
20-
ELSE()
18+
if(WIN32)
19+
add_compile_options(/openmp)
20+
# Only apply /O2 if the configuration is RELEASE.
21+
# This prevents a conflict with /RTC1 in DEBUG builds.
22+
add_compile_options($<$<CONFIG:RELEASE>:/O2>
23+
else()
2124
add_compile_options(-msse4.1 -O3 -flto=auto)
22-
ENDIF()
25+
endif()
2326

2427
if(APPLE)
2528
include_directories(
@@ -36,7 +39,7 @@ if(APPLE)
3639
)
3740
endif()
3841

39-
INCLUDE(../GetPybind11.cmake)
42+
include(../GetPybind11.cmake)
4043
pybind11_add_module(qsim_sse pybind_main_sse.cpp)
4144

4245
target_link_libraries(qsim_sse PUBLIC OpenMP::OpenMP_CXX)

0 commit comments

Comments
 (0)