-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
149 lines (127 loc) · 5.24 KB
/
CMakeLists.txt
File metadata and controls
149 lines (127 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
cmake_minimum_required(VERSION 3.15)
project(QuadBLAS)
# Set build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
# Set C++ standard globally
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find OpenMP (your existing code)
if(APPLE)
find_library(OpenMP_LIBRARY
NAMES omp gomp iomp5
PATHS /opt/homebrew/lib /usr/local/lib /opt/homebrew/opt/libomp/lib
NO_DEFAULT_PATH
)
find_path(OpenMP_INCLUDE_DIR
NAMES omp.h
PATHS /opt/homebrew/include /usr/local/include /opt/homebrew/opt/libomp/include
NO_DEFAULT_PATH
)
if(OpenMP_LIBRARY AND OpenMP_INCLUDE_DIR)
set(OpenMP_FOUND TRUE)
add_library(OpenMP::OpenMP_CXX UNKNOWN IMPORTED)
set_target_properties(OpenMP::OpenMP_CXX PROPERTIES
IMPORTED_LOCATION "${OpenMP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OpenMP_INCLUDE_DIR}"
INTERFACE_COMPILE_OPTIONS "-Xpreprocessor;-fopenmp"
)
message(STATUS "Found OpenMP: ${OpenMP_LIBRARY}")
else()
set(OpenMP_FOUND FALSE)
message(WARNING "OpenMP not found. Install with: brew install libomp")
endif()
else()
find_package(OpenMP)
endif()
# Handle SLEEF library (fixed for your environment)
set(SLEEF_CUSTOM_ROOT "$ENV{SLEEF_ROOT}")
if(SLEEF_CUSTOM_ROOT)
set(SLEEF_INCLUDE_DIR "${SLEEF_CUSTOM_ROOT}/include")
set(SLEEF_LIB_DIR "${SLEEF_CUSTOM_ROOT}/lib")
if(NOT EXISTS ${SLEEF_INCLUDE_DIR} OR NOT EXISTS ${SLEEF_LIB_DIR})
message(FATAL_ERROR "SLEEF installation not found at: ${SLEEF_CUSTOM_ROOT}")
endif()
find_library(SLEEF_LIBRARY
NAMES sleef
PATHS ${SLEEF_LIB_DIR}
NO_DEFAULT_PATH
)
find_library(SLEEFQUAD_LIBRARY
NAMES sleefquad
PATHS ${SLEEF_LIB_DIR}
NO_DEFAULT_PATH
)
if(SLEEF_LIBRARY AND SLEEFQUAD_LIBRARY)
set(SLEEF_LIBRARIES ${SLEEF_LIBRARY} ${SLEEFQUAD_LIBRARY})
message(STATUS "Using SLEEF from: ${SLEEF_CUSTOM_ROOT}")
message(STATUS "Found SLEEF libraries: ${SLEEF_LIBRARIES}")
else()
message(FATAL_ERROR "SLEEF libraries not found in ${SLEEF_LIB_DIR}")
endif()
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(SLEEF REQUIRED sleef)
endif()
# Add Google Benchmark with proper Release configuration
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/benchmark/CMakeLists.txt")
# Configure Google Benchmark for Release mode and disable testing
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable testing of the benchmark library.")
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Enable Google Test in benchmark.")
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON CACHE BOOL "Allow benchmark to download dependencies.")
# Ensure benchmark is built in Release mode
set(CMAKE_BUILD_TYPE_BACKUP ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE Release)
add_subdirectory(third_party/benchmark)
# Restore original build type
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_BACKUP})
set(GOOGLE_BENCHMARK_AVAILABLE TRUE)
message(STATUS "Google Benchmark added (Release mode)")
else()
set(GOOGLE_BENCHMARK_AVAILABLE FALSE)
message(STATUS "Google Benchmark not found (run: git submodule add https://github.com/google/benchmark.git third_party/benchmark)")
endif()
# Create executables
add_executable(quadblas_test test_quadblas.cpp)
add_executable(quadblas_benchmark_legacy benchmarks/legacy_benchmark.cpp)
# Add Google Benchmark executable if available
if(GOOGLE_BENCHMARK_AVAILABLE)
add_executable(quadblas_benchmark benchmarks/benchmark.cpp)
endif()
# Common configuration function
function(configure_target target_name)
target_compile_features(${target_name} PRIVATE cxx_std_17)
# Set optimization flags based on build type
target_compile_options(${target_name} PRIVATE
$<$<CONFIG:Release>:-O3 -march=native -ffast-math -DNDEBUG>
$<$<CONFIG:Debug>:-g -O0 -fsanitize=address>
$<$<CONFIG:RelWithDebInfo>:-O2 -g -march=native -ffast-math>
)
target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if(SLEEF_CUSTOM_ROOT)
target_include_directories(${target_name} PRIVATE ${SLEEF_INCLUDE_DIR})
else()
target_include_directories(${target_name} PRIVATE ${SLEEF_INCLUDE_DIRS})
target_link_directories(${target_name} PRIVATE ${SLEEF_LIBRARY_DIRS})
target_compile_definitions(${target_name} PRIVATE ${SLEEF_CFLAGS_OTHER})
endif()
target_link_libraries(${target_name}
${SLEEF_LIBRARIES}
$<$<BOOL:${OpenMP_FOUND}>:OpenMP::OpenMP_CXX>
$<$<CONFIG:Debug>:-fsanitize=address>
)
endfunction()
# Configure targets
configure_target(quadblas_test)
configure_target(quadblas_benchmark_legacy)
# Configure Google Benchmark target with proper linking
if(GOOGLE_BENCHMARK_AVAILABLE)
configure_target(quadblas_benchmark)
target_link_libraries(quadblas_benchmark benchmark::benchmark)
endif()
message(STATUS "=== Configuration ===")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "OpenMP: ${OpenMP_FOUND}")
message(STATUS "SLEEF: ${SLEEF_LIBRARIES}")
message(STATUS "Google Benchmark: ${GOOGLE_BENCHMARK_AVAILABLE}")