1+ cmake_minimum_required (VERSION 3.24.0 )
2+ project (ELEQTRONeX VERSION 1.0.0)
3+
4+ # In-source tree builds are not supported
5+ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
6+ message (FATAL_ERROR "Building in-source is not supported! "
7+ "Create a build directory and remove "
8+ "${CMAKE_SOURCE_DIR } /CMakeCache.txt ${CMAKE_SOURCE_DIR } /CMakeFiles/" )
9+ endif ()
10+
11+ # Set C++17 standard
12+ set (CMAKE_CXX_STANDARD 17)
13+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
14+ set (CMAKE_CXX_EXTENSIONS OFF )
15+
16+ # Change default build type to Release
17+ if (NOT CMAKE_BUILD_TYPE )
18+ set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE )
19+ endif ()
20+
21+ # Options - mirror GNUmakefile defaults but allow flexibility
22+ option (ELEQTRONeX_APP "Build the ELEQTRONeX executable application" ON )
23+ option (ELEQTRONeX_MPI "Multi-node support (message-passing)" ON )
24+ option (ELEQTRONeX_EB "Embedded boundary support" ON )
25+ option (ELEQTRONeX_TRANSPORT "Transport support" ON )
26+ option (ELEQTRONeX_TIME_DEPENDENT "Time-dependent support" ON )
27+ option (ELEQTRONeX_BROYDEN_PARALLEL "Broyden parallel support" ON )
28+ option (ELEQTRONeX_HYPRE "HYPRE support" OFF )
29+
30+ # Dependency options
31+ option (ELEQTRONeX_amrex_internal "Download & build AMReX" ON )
32+
33+ # Print options
34+ option (ELEQTRONeX_PRINT_HIGH "Enable high level debug printing" OFF )
35+ option (ELEQTRONeX_PRINT_MEDIUM "Enable medium level debug printing" OFF )
36+ option (ELEQTRONeX_PRINT_LOW "Enable low level debug printing" OFF )
37+ option (ELEQTRONeX_PRINT_NAME "Enable function name debug printing" OFF )
38+
39+ # Compute backend selection
40+ set (ELEQTRONeX_COMPUTE_VALUES NOACC OMP CUDA HIP)
41+ set (ELEQTRONeX_COMPUTE NOACC CACHE STRING "On-node, accelerated computing backend (NOACC/OMP/CUDA/HIP)" )
42+ set_property (CACHE ELEQTRONeX_COMPUTE PROPERTY STRINGS ${ELEQTRONeX_COMPUTE_VALUES} )
43+ if (NOT ELEQTRONeX_COMPUTE IN_LIST ELEQTRONeX_COMPUTE_VALUES)
44+ message (FATAL_ERROR "ELEQTRONeX_COMPUTE (${ELEQTRONeX_COMPUTE} ) must be one of ${ELEQTRONeX_COMPUTE_VALUES} " )
45+ endif ()
46+
47+ # Set dimensions (3D only for ELEQTRONeX)
48+ set (ELEQTRONeX_DIMS 3 CACHE STRING "Simulation dimensionality (3D only)" )
49+
50+ # Include AMReX dependency management
51+ include (${CMAKE_CURRENT_SOURCE_DIR } /cmake/dependencies/AMReX.cmake )
52+
53+ # Create executable with sophisticated naming like other codes
54+ if (ELEQTRONeX_APP)
55+ # Build binary name
56+ set (binary_name "main3d" )
57+
58+ # Add compiler info
59+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
60+ set (binary_name "${binary_name} .gnu" )
61+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
62+ set (binary_name "${binary_name} .intel" )
63+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
64+ set (binary_name "${binary_name} .clang" )
65+ endif ()
66+
67+ # Add MPI support
68+ if (ELEQTRONeX_MPI)
69+ set (binary_name "${binary_name} .MPI" )
70+ endif ()
71+
72+ # Add EB support
73+ if (ELEQTRONeX_EB)
74+ set (binary_name "${binary_name} .EB" )
75+ endif ()
76+
77+ # Add time-dependent support
78+ if (ELEQTRONeX_TIME_DEPENDENT)
79+ set (binary_name "${binary_name} .TD" )
80+ endif ()
81+
82+ # Add transport support
83+ if (ELEQTRONeX_TRANSPORT)
84+ set (binary_name "${binary_name} .TRAN" )
85+ endif ()
86+
87+ # Add Broyden parallel support
88+ if (ELEQTRONeX_BROYDEN_PARALLEL)
89+ set (binary_name "${binary_name} .BROYPRLL" )
90+ endif ()
91+
92+ # Add SKIPGPU suffix when not using GPU backend (matching gnumake logic)
93+ if (NOT ELEQTRONeX_COMPUTE STREQUAL "CUDA" AND NOT ELEQTRONeX_COMPUTE STREQUAL "HIP" )
94+ set (binary_name "${binary_name} .SKIPGPU" )
95+ endif ()
96+
97+ # Add compute backend
98+ if (ELEQTRONeX_COMPUTE STREQUAL "OMP" )
99+ set (binary_name "${binary_name} .OMP" )
100+ elseif (ELEQTRONeX_COMPUTE STREQUAL "CUDA" )
101+ set (binary_name "${binary_name} .CUDA" )
102+ elseif (ELEQTRONeX_COMPUTE STREQUAL "HIP" )
103+ set (binary_name "${binary_name} .HIP" )
104+ endif ()
105+
106+ # Add HYPRE support
107+ if (ELEQTRONeX_HYPRE)
108+ set (binary_name "${binary_name} .HYPRE" )
109+ endif ()
110+
111+ set (binary_name "${binary_name} .ex" )
112+
113+ add_executable (${binary_name} )
114+
115+ # Add main source files
116+ target_sources (${binary_name} PRIVATE
117+ Source /main.cpp
118+ Source /Code.cpp
119+ )
120+
121+ # Add all subdirectory sources recursively
122+ file (GLOB_RECURSE ELEQTRONeX_SOURCES
123+ "Source/Diagnostics/*.cpp"
124+ "Source/Input/*.cpp"
125+ "Source/Output/*.cpp"
126+ "Source/PostProcessor/*.cpp"
127+ "Source/Solver/*.cpp"
128+ "Source/Utils/*.cpp"
129+ )
130+ target_sources (${binary_name} PRIVATE ${ELEQTRONeX_SOURCES} )
131+
132+ # Include directories
133+ target_include_directories (${binary_name} PRIVATE
134+ ${CMAKE_CURRENT_SOURCE_DIR } /Source
135+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Diagnostics
136+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Input
137+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Input/BoundaryConditions
138+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Input/GeometryProperties
139+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Input/MacroscopicProperties
140+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Output
141+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/PostProcessor
142+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Solver
143+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Solver/Electrostatics
144+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Solver/Transport
145+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Utils
146+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Utils/CodeUtils
147+ ${CMAKE_CURRENT_SOURCE_DIR } /Source/Utils/SelectWarpXUtils
148+ )
149+
150+ # Link AMReX (AMReX will automatically link HYPRE if it was built with HYPRE support)
151+ target_link_libraries (${binary_name} PRIVATE AMReX::amrex )
152+
153+ # Set compile definitions based on options
154+ # Matching gnumake here - this will be a redefinition as a workaround for nonstandard code
155+ if (ELEQTRONeX_EB)
156+ target_compile_definitions (${binary_name} PRIVATE AMREX_USE_EB )
157+ endif ()
158+
159+ if (ELEQTRONeX_TIME_DEPENDENT)
160+ target_compile_definitions (${binary_name} PRIVATE TIME_DEPENDENT )
161+ endif ()
162+
163+ if (ELEQTRONeX_TRANSPORT)
164+ target_compile_definitions (${binary_name} PRIVATE USE_TRANSPORT )
165+ endif ()
166+
167+ if (ELEQTRONeX_BROYDEN_PARALLEL)
168+ target_compile_definitions (${binary_name} PRIVATE BROYDEN_PARALLEL )
169+ endif ()
170+
171+ # Matching gnumake logic: skip GPU optimization when not using GPU backend
172+ if (NOT ELEQTRONeX_COMPUTE STREQUAL "CUDA" AND NOT ELEQTRONeX_COMPUTE STREQUAL "HIP" )
173+ target_compile_definitions (${binary_name} PRIVATE BROYDEN_SKIP_GPU_OPTIMIZATION )
174+ endif ()
175+
176+ # Print debug options - matches Make.Code logic
177+ if (ELEQTRONeX_PRINT_HIGH)
178+ target_compile_definitions (${binary_name} PRIVATE PRINT_HIGH PRINT_MEDIUM PRINT_LOW PRINT_NAME )
179+ elseif (ELEQTRONeX_PRINT_MEDIUM)
180+ target_compile_definitions (${binary_name} PRIVATE PRINT_MEDIUM PRINT_LOW PRINT_NAME )
181+ elseif (ELEQTRONeX_PRINT_LOW)
182+ target_compile_definitions (${binary_name} PRIVATE PRINT_LOW PRINT_NAME )
183+ elseif (ELEQTRONeX_PRINT_NAME)
184+ target_compile_definitions (${binary_name} PRIVATE PRINT_NAME )
185+ endif ()
186+
187+ # Handle CUDA compilation like MagneX and FerroX
188+ if (ELEQTRONeX_COMPUTE STREQUAL "CUDA" )
189+ # AMReX helper function: propagate CUDA specific target & source properties
190+ setup_target_for_cuda_compilation (${binary_name} )
191+ target_compile_features (${binary_name} PUBLIC cuda_std_17 )
192+ set_target_properties (${binary_name} PROPERTIES
193+ CUDA_EXTENSIONS OFF
194+ CUDA_STANDARD_REQUIRED ON
195+ )
196+ else ()
197+ target_compile_features (${binary_name} PUBLIC cxx_std_17 )
198+ set_target_properties (${binary_name} PROPERTIES
199+ CXX_EXTENSIONS OFF
200+ CXX_STANDARD_REQUIRED ON
201+ )
202+ endif ()
203+
204+ # Set output directory
205+ set_target_properties (${binary_name} PROPERTIES
206+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR }
207+ )
208+
209+ # Create simple symlink for convenience
210+ add_custom_command (TARGET ${binary_name} POST_BUILD
211+ COMMAND ${CMAKE_COMMAND } -E create_symlink
212+ ${binary_name}
213+ ${CMAKE_BINARY_DIR } /eleqtronex
214+ COMMENT "Creating symlink eleqtronex -> ${binary_name} "
215+ )
216+ endif ()
0 commit comments