Skip to content

feat: upgrade build system to CMake, remove hardcoded paths, and add migration documentation#1

Merged
samcom12 merged 3 commits intomainfrom
copilot/upgrade-build-system-to-cmake
Apr 17, 2026
Merged

feat: upgrade build system to CMake, remove hardcoded paths, and add migration documentation#1
samcom12 merged 3 commits intomainfrom
copilot/upgrade-build-system-to-cmake

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 12, 2026

Summary

Migrates the MicroSim build system from a collection of independent hand-written Makefiles to a unified CMake 3.18+ build system. All original Makefiles are retained alongside the new CMakeLists.txt files to ease the transition. Hardcoded absolute paths in the existing Makefiles have also been replaced with portable, overridable environment-variable-based defaults.

Changes

New files

File Purpose
CMakeLists.txt Top-level entry point; enables/disables each solver via BUILD_* flags
Grand_Potential_Serial/CMakeLists.txt Serial solver (gcc + libm)
Grand_Potential_MPI/CMakeLists.txt MPI solver (MPI + HDF5 parallel + GSL)
KKS_CuFFT/CMakeLists.txt CUDA cuFFT solver (nvcc + cuFFT)
KKS_FD_CUDA_MPI/CMakeLists.txt CUDA+MPI solver (CUDA separable compilation + MPI + HDF5 + GSL + optional cuFFTMp)
KKS_OpenCl/CMakeLists.txt OpenCL solver (MPI + OpenCL + HDF5 + GSL)
Cahn_Hilliard_FFT_2D/CMakeLists.txt Cahn-Hilliard FFT solver (FFTW3)
cmake/FindFFTW3.cmake Custom CMake find module for FFTW3 (no built-in CMake support)
docs/cmake_upgrade.md Migration guide with prerequisites, quick-start, per-solver notes, and troubleshooting

Makefile hardcoded path fixes

Makefile Old hardcoded path(s) Replacement
Grand_Potential_MPI/Makefile /share/apps/gsl/lib, /share/apps/gsl/include GSL_ROOT_DIR auto-detected via gsl-config --prefix, fully overridable
KKS_OpenCl/Makefile $(HOME)/gsl_2_7/..., /usr/local/cuda/..., /usr/include/hdf5/openmpi CUDA_HOME, GSL_ROOT_DIR, HDF5_INC_DIR variables with auto-detection fallbacks
KKS_FD_CUDA_MPI/Makefile Spack-hash specific HDF5 and GSL paths Empty defaults (HDF5_HOME ?=, GSL_HOME ?=) with inline instructions; fixed NVHPC_ROOT default path

Out of scope (build system unchanged)

  • Grand_potential_AMReX/ — uses AMReX's own GNUmake infrastructure
  • Grand_potential_OpenFOAM/ and Bridgman/ — use OpenFOAM's wmake

How to build

CMake (recommended)

# All solvers
cmake -S . -B build
cmake --build build -j8

# Single solver only
cmake -S . -B build -DBUILD_GRAND_POTENTIAL_SERIAL=ON \
      -DBUILD_GRAND_POTENTIAL_MPI=OFF \
      -DBUILD_KKS_CUFFT=OFF \
      -DBUILD_KKS_FD_CUDA_MPI=OFF \
      -DBUILD_KKS_OPENCL=OFF \
      -DBUILD_CAHN_HILLIARD_FFT_2D=OFF
cmake --build build -j8

Key configuration options: CUDA_ARCH (default 70), ENABLE_HDF5, ENABLE_CUFFTMP, FFTW3_ROOT, GSL_ROOT_DIR, HDF5_ROOT.

Make (with portable paths)

# Override library roots as needed, e.g.:
cd Grand_Potential_MPI && make GSL_ROOT_DIR=/usr/local
cd KKS_OpenCl && make CUDA_HOME=/usr/local/cuda GSL_ROOT_DIR=/usr/local
cd KKS_FD_CUDA_MPI && make HDF5_HOME=/opt/hdf5 GSL_HOME=/usr/local

Testing

The Grand_Potential_Serial solver was verified to compile cleanly and produce the microsim_gp executable (157 KB ELF binary) via both make and cmake --build using GCC 13.3.0. The remaining solvers require CUDA, MPI, and/or HDF5 toolchains — their CMake configuration syntax was validated up to the dependency-not-found stage, and their Makefile path variables are confirmed portable.

Copilot AI and others added 2 commits April 12, 2026 11:20
- Add top-level CMakeLists.txt with per-solver opt-in flags
- Add Grand_Potential_Serial/CMakeLists.txt (gcc + libm)
- Add Grand_Potential_MPI/CMakeLists.txt (MPI + HDF5 + GSL)
- Add KKS_CuFFT/CMakeLists.txt (CUDA + cuFFT)
- Add KKS_FD_CUDA_MPI/CMakeLists.txt (CUDA separable + MPI + HDF5 + GSL)
- Add KKS_OpenCl/CMakeLists.txt (MPI + OpenCL + HDF5 + GSL)
- Add Cahn_Hilliard_FFT_2D/CMakeLists.txt (FFTW3)
- Add cmake/FindFFTW3.cmake custom find module
- Add docs/cmake_upgrade.md migration guide

Agent-Logs-Url: https://github.com/samcom12/MicroSim/sessions/653f1394-fccb-4a78-a946-ddc1e529fd46

Co-authored-by: samcom12 <13285627+samcom12@users.noreply.github.com>
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 12, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copilot AI requested a review from samcom12 April 12, 2026 11:23
@samcom12
Copy link
Copy Markdown
Owner

@copilot remove any hardcoded paths from makefile and build microsim wih the changes and see if it creates executables properly

…efaults

- Grand_Potential_MPI: replace /share/apps/gsl/* with GSL_ROOT_DIR
  auto-detected via gsl-config, fully overridable
- KKS_OpenCl: replace $(HOME)/gsl_2_7, /usr/local/cuda, /usr/include/hdf5
  with CUDA_HOME / GSL_ROOT_DIR / HDF5_INC_DIR variables
- KKS_FD_CUDA_MPI: remove spack-hash HDF5 and GSL paths; use empty
  defaults with inline instructions; fix NVHPC_ROOT default path

Build verified: Grand_Potential_Serial produces microsim_gp executable
via both `make` and `cmake --build`.

Agent-Logs-Url: https://github.com/samcom12/MicroSim/sessions/83c47819-1f44-4cb4-a635-26b7e4367139

Co-authored-by: samcom12 <13285627+samcom12@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Apr 17, 2026

@copilot remove any hardcoded paths from makefile and build microsim wih the changes and see if it creates executables properly

Done in commit c2935c9. Three Makefiles had hardcoded absolute paths — here's what was changed:

Makefile Old hardcoded path(s) Replacement
Grand_Potential_MPI /share/apps/gsl/lib, /share/apps/gsl/include GSL_ROOT_DIR auto-detected via gsl-config --prefix, fully overridable
KKS_OpenCl $(HOME)/gsl_2_7/..., /usr/local/cuda/..., /usr/include/hdf5/openmpi GSL_ROOT_DIR, CUDA_HOME, HDF5_INC_DIR variables with auto-detection fallbacks
KKS_FD_CUDA_MPI Spack-hash specific HDF5 and GSL paths Empty defaults with inline instructions on how to supply them

Build verified: Grand_Potential_Serial produces the microsim_gp executable successfully via both make and cmake --build:

$ cd Grand_Potential_Serial && make
gcc -I.  -c -o microsim_gp.o microsim_gp.c
gcc -o microsim_gp microsim_gp.o -I. -lm
$ ls -lh microsim_gp
-rwxrwxr-x 1 runner runner 157K microsim_gp

The other solvers (MPI, CUDA, OpenCL) require toolchains (MPI, CUDA toolkit, OpenCL SDK) not present in this sandbox, so they can't be compiled here, but the Makefile paths are now portable.

Copilot AI changed the title feat: upgrade build system to CMake and add migration documentation feat: upgrade build system to CMake, remove hardcoded paths, and add migration documentation Apr 17, 2026
Copy link
Copy Markdown
Owner

@samcom12 samcom12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It covers all required changes

@samcom12
Copy link
Copy Markdown
Owner

Can be merged

@samcom12 samcom12 closed this Apr 17, 2026
@samcom12
Copy link
Copy Markdown
Owner

needs to merge

@samcom12 samcom12 reopened this Apr 17, 2026
@samcom12 samcom12 marked this pull request as ready for review April 17, 2026 06:37
@samcom12 samcom12 merged commit 4dbcda8 into main Apr 17, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants