Skip to content

Commit 6960e64

Browse files
Compiling on conda-forge's Macs (#59)
* First try + updatet to cmake 3.21 + introduced presets + on linux both gcc and clang working + added markdown for overview * Lose OpenMP as dependency + gcc and clang-linux working, same speed for test * Loosen compile options * Introduce virtual destructors to circumvent main.cpp:32:9: warning: delete called on 'Matmodel<1>' that is abstract but has non-virtual destructor [-Wdelete-abstract-non-virtual-dtor] 32 | delete matmodel; given through clang. + also applied the same to Solver * Remove some of the hardcoded compiler paths for clang-macos * Delete all hardcoded compiler paths * Update CMake Setting + uncomment compile options + remove unnecessary comment + remove doubled CMake min version + introduce CXX_FLAGS for gcc in preset + also in parts for Clang, -fmax-errors does not exist there + reintroduce RPATH-logic for Apple -> don't understand it + add condition to mac presets -> only loose, as darwin is open-source and could NOT be apple... but seems to be standard vs APPLE-check.... * removed presets not used in feedstock --------- Co-authored-by: sanathkeshav <[email protected]>
1 parent 54dd03a commit 6960e64

File tree

4 files changed

+50
-33
lines changed

4 files changed

+50
-33
lines changed

CMakeLists.txt

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.0...3.28)
1+
cmake_minimum_required(VERSION 3.21)
22

33
# ##############################################################################
44
# GENERAL SETTINGS
@@ -17,7 +17,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1717

1818
# with -fno-implicit-templates I get linker errors when using std:: stuff
1919
# TODO: should be developer specific, by using e.g. CMake Presets
20-
set(CMAKE_CXX_FLAGS "-fmax-errors=1 -O3")
20+
set(CMAKE_CXX_FLAGS "-O3")
2121
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
2222

2323
# IPO
@@ -54,7 +54,6 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
5454
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
5555

5656
# From https://stackoverflow.com/questions/73248130/how-to-avoid-the-removal-of-the-rpath-during-cmake-install-step
57-
5857
# Set RPATH to be relative and honor user overrides, whether at the command line or FetchContent
5958
if(APPLE)
6059
set(RPATH_BASE "@loader_path")
@@ -115,36 +114,8 @@ add_library(FANS::FANS ALIAS FANS_FANS)
115114
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
116115

117116
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
118-
# Detecting if there is avx2 and fma support on linux
119-
# Deteced together, because these flags were introduced by Intel Haskell 4th. Gen
120-
# Distinguishing between mac/linux because lscpu is used, which is not supported on mac.
121-
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
122-
# macOS: Assume AVX2 and FMA are supported as per requirement
123-
message(STATUS "Assuming AVX2 and FMA support on macOS; using -mavx2 and -mfma.")
124-
target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma)
125-
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
126-
# Linux: Check for AVX2 support using lscpu
127-
execute_process(COMMAND lscpu OUTPUT_VARIABLE LSCPU_OUTPUT ERROR_QUIET)
128-
129-
# Default to AVX; enable AVX2 if supported by hardware
130-
set(FANS_USE_AVX2 FALSE)
131-
if (LSCPU_OUTPUT MATCHES "avx2")
132-
set(FANS_USE_AVX2 TRUE)
133-
endif()
134-
135-
# Apply compiler options based on hardware detection
136-
if (FANS_USE_AVX2)
137-
message(STATUS "AVX2 and FMA supported by hardware; using -mavx2 and -mfma.")
138-
target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma)
139-
else()
140-
message(WARNING "AVX2 and FMA not supported by hardware; falling back to AVX.")
141-
target_compile_options(FANS_FANS PUBLIC -mavx)
142-
endif()
143-
else()
144-
message(WARNING "Unsupported system for AVX2 detection; defaulting to -mavx.")
145-
target_compile_options(FANS_FANS PUBLIC -mavx)
146-
endif()
147-
endif()
117+
target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma)
118+
endif ()
148119

149120
add_executable(FANS_main)
150121
add_custom_command(

CMakePresets.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "gcc-release",
6+
"displayName": "GCC Release (Linux)",
7+
"description": "GCC compiler with Release build type",
8+
"generator": "Unix Makefiles",
9+
"binaryDir": "${sourceDir}/build",
10+
"cacheVariables": {
11+
"CMAKE_BUILD_TYPE": "Release",
12+
"CMAKE_CXX_FLAGS": "-fmax-errors=1 -O3",
13+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
14+
}
15+
},
16+
{
17+
"name": "clang-release-macos",
18+
"displayName": "Clang Release (macOS)",
19+
"description": "macOS system Clang for Release",
20+
"generator": "Unix Makefiles",
21+
"binaryDir": "${sourceDir}/build",
22+
"cacheVariables": {
23+
"CMAKE_BUILD_TYPE": "Release",
24+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
25+
},
26+
"condition": {
27+
"type": "equals",
28+
"lhs": "${hostSystemName}",
29+
"rhs": "Darwin"
30+
}
31+
}
32+
],
33+
"buildPresets": [
34+
{
35+
"name": "gcc-release",
36+
"configurePreset": "gcc-release"
37+
},
38+
{
39+
"name": "clang-release-macos",
40+
"configurePreset": "clang-release-macos"
41+
}
42+
]
43+
}

include/matmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Matmodel {
4343

4444
vector<double> macroscale_loading;
4545

46+
virtual ~Matmodel() = default;
47+
4648
protected:
4749
double l_e_x;
4850
double l_e_y;

include/solver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ template <int howmany>
99
class Solver {
1010
public:
1111
Solver(Reader reader, Matmodel<howmany> *matmodel);
12+
virtual ~Solver() = default;
1213

1314
Reader reader;
1415

0 commit comments

Comments
 (0)