Skip to content

Commit a469ddd

Browse files
committed
Configure LTO in a portable way
CMake has features to handle LTO for different compilers and platforms. Better to use this than to add our own lto options.
1 parent f8f1ab1 commit a469ddd

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ elseif(APPLE AND NOT CMAKE_APPLE_SILICON_PROCESSOR)
7676
check_cpu_support("sse4_1" CPU_SUPPORTS_SSE4)
7777
endif()
7878

79+
# Configure LTO for compilers that support it.
80+
include(CheckIPOSupported)
81+
check_ipo_supported(RESULT HAVE_LTO)
82+
7983
# ~~~~~ Configure the build ~~~~~
8084

8185
if(WIN32)
@@ -84,6 +88,10 @@ else()
8488
add_compile_options(-O3 -D_GLIBCXX_USE_CXX11_ABI=1)
8589
endif()
8690

91+
if(HAVE_LTO)
92+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
93+
endif()
94+
8795
include(dev_tools/cmake/GetPybind11.cmake)
8896

8997
# Always build the basic part.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2019 Google LLC. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cmake_minimum_required(VERSION 3.31)
16+
project(qsim)
17+
18+
IF (WIN32)
19+
add_compile_options(/arch:AVX512)
20+
ELSEIF(HAVE_AVX512_10)
21+
add_compile_options(-mavx10.1-512 -mbmi2)
22+
ELSE()
23+
add_compile_options(-mavx512f -mbmi2)
24+
ENDIF()
25+
26+
INCLUDE(../../dev_tools/cmake/GetPybind11.cmake)
27+
pybind11_add_module(qsim_avx512 pybind_main_avx512.cpp)
28+
29+
if(OpenMP_CXX_FOUND)
30+
target_link_libraries(qsim_avx512 PUBLIC OpenMP::OpenMP_CXX)
31+
endif()

pybind_interface/sse/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ pybind11_add_module(qsim_sse pybind_main_sse.cpp)
5757
if(OpenMP_CXX_FOUND)
5858
target_link_libraries(qsim_sse PUBLIC pybind11::headers OpenMP::OpenMP_CXX)
5959
endif()
60-

0 commit comments

Comments
 (0)