Skip to content

Commit e2c35ec

Browse files
committed
Consolidate common flags into the top-level CMakeLists.txt
Each of 8 or so `pybind_interface/` subdirectories had `CMakeLists.txt` files that contained the same text for setting certain compilation flags. This commit removes the duplication in favor of putting the settings into the top-level CMake file.
1 parent 4658564 commit e2c35ec

File tree

9 files changed

+28
-143
lines changed

9 files changed

+28
-143
lines changed

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ endif()
7777
set(CMAKE_CXX_STANDARD 17)
7878
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
7979

80+
# Options propagated to all sub-cmakefiles.
81+
if(WIN32)
82+
add_compile_options(/O2 /std:c++17 /openmp)
83+
else()
84+
add_compile_options(-O3 -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=1 -flto=auto)
85+
endif()
86+
8087
# Always build the basic part.
8188
add_subdirectory(pybind_interface/basic)
8289
add_subdirectory(pybind_interface/decide)
@@ -105,6 +112,21 @@ if(NOT CMAKE_APPLE_SILICON_PROCESSOR)
105112
endif()
106113
endif()
107114

115+
if(APPLE)
116+
include_directories(
117+
"/usr/local/include"
118+
"/usr/local/opt/llvm/include"
119+
"/opt/homebrew/include"
120+
"/opt/homebrew/opt/llvm@19/include"
121+
)
122+
link_directories(
123+
"/usr/local/lib"
124+
"/usr/local/opt/llvm/lib"
125+
"/opt/homebrew/lib"
126+
"/opt/homebrew/opt/llvm@19/lib"
127+
)
128+
endif()
129+
108130

109131
# ~~~~~ Print misc. info ~~~~~
110132

pybind_interface/avx2/CMakeLists.txt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,11 @@ cmake_minimum_required(VERSION 3.31)
1616
project(qsim)
1717

1818
IF (WIN32)
19-
set(CMAKE_CXX_FLAGS "/arch:AVX2 /O2 /openmp")
19+
set(CMAKE_CXX_FLAGS "/arch:AVX2")
2020
ELSE()
21-
set(CMAKE_CXX_FLAGS "-mavx2 -mfma -O3")
21+
set(CMAKE_CXX_FLAGS "-mavx2 -mfma")
2222
ENDIF()
2323

24-
if(APPLE)
25-
include_directories(
26-
"/usr/local/include"
27-
"/usr/local/opt/llvm/include"
28-
"/opt/homebrew/include"
29-
"/opt/homebrew/opt/llvm@19/include"
30-
)
31-
link_directories(
32-
"/usr/local/lib"
33-
"/usr/local/opt/llvm/lib"
34-
"/opt/homebrew/lib"
35-
"/opt/homebrew/opt/llvm@19/lib"
36-
)
37-
endif()
38-
3924
INCLUDE(../GetPybind11.cmake)
4025
pybind11_add_module(qsim_avx2 pybind_main_avx2.cpp)
4126

pybind_interface/avx512/CMakeLists.txt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,11 @@ cmake_minimum_required(VERSION 3.31)
1616
project(qsim)
1717

1818
IF (WIN32)
19-
set(CMAKE_CXX_FLAGS "/arch:AVX512 /O2 /openmp")
19+
set(CMAKE_CXX_FLAGS "/arch:AVX512")
2020
ELSE()
21-
set(CMAKE_CXX_FLAGS "-mavx512f -mbmi2 -O3")
21+
set(CMAKE_CXX_FLAGS "-mavx512f -mbmi2")
2222
ENDIF()
2323

24-
if(APPLE)
25-
include_directories(
26-
"/usr/local/include"
27-
"/usr/local/opt/llvm/include"
28-
"/opt/homebrew/include"
29-
"/opt/homebrew/opt/llvm@19/include"
30-
)
31-
link_directories(
32-
"/usr/local/lib"
33-
"/usr/local/opt/llvm/lib"
34-
"/opt/homebrew/lib"
35-
"/opt/homebrew/opt/llvm@19/lib"
36-
)
37-
endif()
38-
3924
INCLUDE(../GetPybind11.cmake)
4025
pybind11_add_module(qsim_avx512 pybind_main_avx512.cpp)
4126

pybind_interface/basic/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,6 @@
1515
cmake_minimum_required(VERSION 3.31)
1616
project(qsim)
1717

18-
if(WIN32)
19-
set(CMAKE_CXX_FLAGS "/O2 /openmp")
20-
else()
21-
set(CMAKE_CXX_FLAGS "-O3")
22-
endif()
23-
24-
if(APPLE)
25-
include_directories(
26-
"/usr/local/include"
27-
"/usr/local/opt/llvm/include"
28-
"/opt/homebrew/include"
29-
"/opt/homebrew/opt/llvm@19/include"
30-
)
31-
link_directories(
32-
"/usr/local/lib"
33-
"/usr/local/opt/llvm/lib"
34-
"/opt/homebrew/lib"
35-
"/opt/homebrew/opt/llvm@19/lib"
36-
)
37-
endif()
38-
3918
INCLUDE(../GetPybind11.cmake)
4019
pybind11_add_module(qsim_basic pybind_main_basic.cpp)
4120

pybind_interface/cuda/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,6 @@
1515
cmake_minimum_required(VERSION 3.31)
1616
project(qsim LANGUAGES CXX CUDA)
1717

18-
if(WIN32)
19-
set(CMAKE_CXX_FLAGS "/O2 /openmp")
20-
else()
21-
set(CMAKE_CXX_FLAGS "-O3")
22-
endif()
23-
24-
if(APPLE)
25-
include_directories(
26-
"/usr/local/include"
27-
"/usr/local/opt/llvm/include"
28-
"/opt/homebrew/include"
29-
"/opt/homebrew/opt/llvm@19/include"
30-
)
31-
link_directories(
32-
"/usr/local/lib"
33-
"/usr/local/opt/llvm/lib"
34-
"/opt/homebrew/lib"
35-
"/opt/homebrew/opt/llvm@19/lib"
36-
)
37-
endif()
38-
3918
include(../GetPybind11.cmake)
4019
include(../GetCUDAARCHS.cmake)
4120

pybind_interface/custatevec/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,6 @@
1515
cmake_minimum_required(VERSION 3.31)
1616
project(qsim LANGUAGES CXX CUDA)
1717

18-
if(WIN32)
19-
set(CMAKE_CXX_FLAGS "/O2 /openmp")
20-
else()
21-
set(CMAKE_CXX_FLAGS "-O3")
22-
endif()
23-
24-
if(APPLE)
25-
include_directories(
26-
"/usr/local/include"
27-
"/usr/local/opt/llvm/include"
28-
"/opt/homebrew/include"
29-
"/opt/homebrew/opt/llvm@19/include"
30-
)
31-
link_directories(
32-
"/usr/local/lib"
33-
"/usr/local/opt/llvm/lib"
34-
"/opt/homebrew/lib"
35-
"/opt/homebrew/opt/llvm@19/lib"
36-
)
37-
endif()
38-
3918
INCLUDE(../GetPybind11.cmake)
4019
find_package(Python3 3.10 REQUIRED)
4120

pybind_interface/decide/CMakeLists.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,6 @@ project(qsim LANGUAGES CXX)
1818
include(CheckLanguage)
1919
check_language(CUDA)
2020

21-
if(WIN32)
22-
set(CMAKE_CXX_FLAGS "/O2 /openmp")
23-
else()
24-
set(CMAKE_CXX_FLAGS "-O3")
25-
endif()
26-
27-
if(APPLE)
28-
include_directories(
29-
"/usr/local/include"
30-
"/usr/local/opt/llvm/include"
31-
"/opt/homebrew/include"
32-
"/opt/homebrew/opt/llvm@19/include"
33-
)
34-
link_directories(
35-
"/usr/local/lib"
36-
"/usr/local/opt/llvm/lib"
37-
"/opt/homebrew/lib"
38-
"/opt/homebrew/opt/llvm@19/lib"
39-
)
40-
endif()
41-
4221
include(../GetPybind11.cmake)
4322

4423
# Configure based on the detected platform

pybind_interface/hip/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
cmake_minimum_required(VERSION 3.31)
1616
project(qsim LANGUAGES CXX HIP)
1717

18-
if(WIN32)
19-
set(CMAKE_CXX_FLAGS "/O2 /openmp")
20-
else()
21-
set(CMAKE_CXX_FLAGS "-O3")
22-
endif()
23-
2418
INCLUDE(../GetPybind11.cmake)
2519
find_package(PythonLibs 3.10 REQUIRED)
2620

pybind_interface/sse/CMakeLists.txt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,8 @@
1515
cmake_minimum_required(VERSION 3.31)
1616
project(qsim)
1717

18-
IF (WIN32)
19-
set(CMAKE_CXX_FLAGS "/O2 /openmp")
20-
ELSE()
21-
set(CMAKE_CXX_FLAGS "-msse4.1 -O3")
22-
ENDIF()
23-
24-
if(APPLE)
25-
include_directories(
26-
"/usr/local/include"
27-
"/usr/local/opt/llvm/include"
28-
"/opt/homebrew/include"
29-
"/opt/homebrew/opt/llvm@19/include"
30-
)
31-
link_directories(
32-
"/usr/local/lib"
33-
"/usr/local/opt/llvm/lib"
34-
"/opt/homebrew/lib"
35-
"/opt/homebrew/opt/llvm@19/lib"
36-
)
18+
if(NOT WIN32)
19+
add_compile_options("-msse4.1")
3720
endif()
3821

3922
INCLUDE(../GetPybind11.cmake)

0 commit comments

Comments
 (0)