Skip to content

Conversation

@asmelko
Copy link

@asmelko asmelko commented Oct 15, 2025

Add CMakeLists.txt support to all sample projects and to PhysiBoSS intracellular project.

To try the new functionality, run:

# Configures project and creates build files in 'build' directory
# Optionally add -G Ninja for a more modern Ninja generator
cmake -B build -S .
# Build everything (all sample projects)
# Optionally specify --target TARGET to build only specific targets, such as biorobots
cmake --build build

The top-level CMakeLists.txt just adds various subdirectories containing other CMake files.
Directories BioFVM, core and modules define libraries, that will be (re)used to build sample projects.
In sample_projects directory, each sample project contains the same CMakeLists.txt which is responsible for building that project.
Intracellular sample projects are slightly different. They reference the library defined in addons directory. As of now, it is just boolean sample projects ported to CMake. See CMakeLists.txt in addons/PhysiBoSS for more info about how the external dependencies are fetched.

Currently, the biggest change compared to Make build is that CMake-built executables are located under the specified build directory. For example, biorobots executable and config files built under build will be located in build/sample_projects/biorobots/ directory.

@asmelko
Copy link
Author

asmelko commented Oct 16, 2025

Added support for the remainder of addons. However, some of them are broken and can not compile even when using Make.

@asmelko
Copy link
Author

asmelko commented Oct 16, 2025

Also, a nice benefit is that I managed to compile PhysiCell on Windows without mingw. I just needed to change create_directory in PhysiCell_settings.cpp. But I needed to turn off MaBoSS compilation - the sources in there are not portable since they use UNIX routines heavily.

Copy link
Collaborator

@drbergman drbergman left a comment

Choose a reason for hiding this comment

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

These changes look, on the whole, good to go. I cannot comment on the value they add since I don't understand how to make use of these. A few other comments below.

Looking forward to getting the power of HPC compute right at our fingertips!

drbergman and others added 2 commits October 16, 2025 09:20
Expanded .gitignore to include all project executables.
@rheiland
Copy link
Collaborator

I get:

$ cmake -B build -S .
-- The CXX compiler identification is AppleClang 17.0.0.17000013
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_CXX_FOUND) 
CMake Warning at BioFVM/CMakeLists.txt:10 (message):
  OpenMP not found.  BioFVM will be built without OpenMP support.


CMake Error at addons/PhysiBoSS/CMakeLists.txt:31 (message):
  Unsupported OS: Darwin

On my Mac, CMake determines my default compiler is clang (which lacks OpenMP), whereas previously, our Makefiles would check for an env var PHYSICELL_CPP and use it if present (primarily intended for Mac brew g++).

@asmelko
Copy link
Author

asmelko commented Oct 16, 2025

On my Mac, CMake determines my default compiler is clang (which lacks OpenMP), whereas previously, our Makefiles would check for an env var PHYSICELL_CPP and use it if present (primarily intended for Mac brew g++).

Yeah, so CMake supports this, but under a different env variable name.
You can either use CC and CXX env variables for setting C and C++ compilers respectively. So sth like this:

CXX=g++ cmake -B build -S .

Or a more modern but verbose variant:

cmake -B build -S . -DCMAKE_CXX_COMPILER=g++ 

Or you can brew install libomp and try if CMake can find it :)

The latter is always set, so we can rely on it in addons CMakeLists
@rheiland
Copy link
Collaborator

rheiland commented Oct 17, 2025

Following up: @asmelko was able to fix some of the issues I was experiencing on a Mac build, so it all seems to be working for me - at least using a brew installed g++. I'm confident it could also be possible to build using Apple's native clang++ (with a brew installed libomp).

At least on a Mac, I think it should be possible to just use the generated Makefile and resulting executable in the root dir (rather than down in /build) and, after modifying the make reset to not do rm -f ./custom_modules/*, be able to run the usual Makefile targets, e.g., make reset, make template, etc, from the root dir. More testing will be needed though.

Finally, on Windows, I encountered the same issues I had when I attempted to use cmake on a previous version of PhysiCell (but were all fixable then and likely now):

  • Note that your own [free, community edition of the] Visual Studio C++ compiler may be different than mine:
C:\Users\randy\git\adam_cmake>cmake --version
cmake version 4.0.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
C:\Users\randy\git\adam_cmake> cmake -B build -S .
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.26100.
-- The CXX compiler identification is MSVC 19.36.32532.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_CXX: -openmp (found version "2.0")
-- Found OpenMP: TRUE (found version "2.0")
-- Configuring done (10.0s)
-- Generating done (0.9s)
-- Build files have been written to: C:/Users/randy/git/adam_cmake/build
---------------------------------------

C:\Users\randy\git\adam_cmake>cmake --build build
MSBuild version 17.6.3+07e294721 for .NET Framework
  1>Checking Build System
  Building Custom Rule C:/Users/randy/git/adam_cmake/BioFVM/CMakeLists.txt
cl : command line  warning D9002: ignoring unknown option '-march=native' [C:\Users\randy\git\adam_cma
ke\build\BioFVM\BioFVM.vcxproj]
...
* numerous warnings, most of which are related to using `sprintf`
C:\Users\randy\git\adam_cmake\BioFVM\BioFVM_MultiCellDS.cpp(384,3): warning C4996: 'sprintf': 
This function or variable may be unsafe. Consider using sprintf_s instead.
...
conversion from 'size_t' to 'int',
...
* lots of these type of errors::
C:\Users\randy\git\adam_cmake\BioFVM\BioFVM_microenvironment.cpp(743,20): error C3016: 'i': 
index variable in OpenMP 'for' statement must have signed integral type

* a couple of these:
C:\Users\randy\git\adam_cmake\modules\PhysiCell_settings.cpp(363,17): error C3861: 'mkdir': 
identifier
 not found

This is for MSVC compilation. Its OpenMP version does not support all pragmas that are used in the project. Also, MSVC was missing some includes containing exports, causing link errors.
@asmelko
Copy link
Author

asmelko commented Oct 18, 2025

At least on a Mac, I think it should be possible to just use the generated Makefile and resulting executable in the root dir (rather than down in /build) and, after modifying the make reset to not do rm -f ./custom_modules/*, be able to run the usual Makefile targets, e.g., make reset, make template, etc, from the root dir. More testing will be needed though.

@rheiland There is another make/cmake functionality, which could be used for moving binaries to specified dirs (such as repo root), which is install. I can add install functionality for each target, which will "install" them into the repo root. I will be happy to hear your thoughts on this.

Finally, on Windows, I encountered the same issues I had when I attempted to use cmake on a previous version of PhysiCell (but were all fixable then and likely now):

Let me start with that there are 2 compilers for windows: cl and relatively new clang (you can download both via Visual Studio Installer). I prefer the latter because it can read the "gnu" C++ flags, so you do not need to have complex os-dependent logic in Make for flags setting. Further, cl has only OpenMP 2.0 support, which is not enough for PhysiCell, while clang has the modern OpenMP 5.0.

Nevertheless, I added a commit that enables building PhysiCell for both Windows compilers. Firstly, I enable OpenMP only if a compiler supports versions >=4, and secondly, I solved mkdir usage in one source file. C++17 has support for filesystem, so I used that. But, since original Makefiles compile with C++11, I use filesystem only conditionally using ifdefs. That way, original makefiles are not touched.

Still, PhysiBoSS uses way too much UNIX routines, so that requires a separate PR for a direct Windows support. Therefore, you still need to configure cmake followingly, when using a Windows compiler:

cmake -B build -S . -DPHYSICELL_BUILD_PHYSIBOSS=OFF

Unsure if _WIN is defined together with MINGW, so implementing it in a safer way.
@rheiland
Copy link
Collaborator

cl has only OpenMP 2.0 support, which is not enough for PhysiCell, while clang has the modern OpenMP 5.0

I don't recall having any issues with building an earlier PhysiCell release with cmake and cl, but could be mistaken. Just curious - what feature of OpenMP are we using that requires 5.0?

Regardless, the following tries to capture my current attempt to use cmake on Windows. It's a virgin machine - no C++ compiler, so I thought it might be possible to just install clang and then have cmake use it:

C:\Program Files\LLVM\bin>clang++.exe --version
clang version 21.1.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

But cmake required installing ninja (and then editing my PATH env var to point to it):

C:\Users\heiland>ninja --version
1.13.1

Then, try to run cmake with clang:

C:\Users\heiland\dev\RePhysiCell-cmake\RePhysiCell-cmake>cmake -G Ninja -Bbuild -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe"
-- The CXX compiler identification is Clang 21.1.4 with GNU-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-4.1/Modules/CMakeTestCXXCompiler.cmake:73 (message):
  The C++ compiler

    "C:/Program Files/LLVM/bin/clang++.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/build/CMakeFiles/CMakeScratch/TryCompile-wmep8o'

    Run Build Command(s): C:/Users/heiland/bin/ninja.exe -v cmTC_c5e8e
    [1/2] C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE   -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -MD -MT CMakeFiles/cmTC_c5e8e.dir/testCXXCompiler.cxx.obj -MF CMakeFiles\cmTC_c5e8e.dir\testCXXCompiler.cxx.obj.d -o CMakeFiles/cmTC_c5e8e.dir/testCXXCompiler.cxx.obj -c C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/build/CMakeFiles/CMakeScratch/TryCompile-wmep8o/testCXXCompiler.cxx
    [2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console -fuse-ld=lld-link CMakeFiles/cmTC_c5e8e.dir/testCXXCompiler.cxx.obj -o cmTC_c5e8e.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_c5e8e.lib -Xlinker /pdb:cmTC_c5e8e.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
    FAILED: [code=1] cmTC_c5e8e.exe
    C:\WINDOWS\system32\cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console -fuse-ld=lld-link CMakeFiles/cmTC_c5e8e.dir/testCXXCompiler.cxx.obj -o cmTC_c5e8e.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_c5e8e.lib -Xlinker /pdb:cmTC_c5e8e.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
    lld-link: error: could not open 'kernel32.lib': no such file or directory
    lld-link: error: could not open 'user32.lib': no such file or directory
    ... (lots more missing libs)

Unsure what to make of this, so I installed Visual Studio Community edition (~5GB). Then re-try the cmake with clang build:

C:\Users\heiland\dev\RePhysiCell-cmake\RePhysiCell-cmake>rm -rf build

C:\Users\heiland\dev\RePhysiCell-cmake\RePhysiCell-cmake> cmake -G Ninja -B build -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe"
-- The CXX compiler identification is Clang 21.1.4 with GNU-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (Required is at least version "4")
-- Could NOT find OpenMP (missing: OpenMP_CXX_FOUND) (Required is at least version "4")
CMake Warning at BioFVM/CMakeLists.txt:10 (message):
  OpenMP not found.  BioFVM will be built without OpenMP support.


-- Configuring done (11.3s)
-- Generating done (0.8s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_C_COMPILER

-- Build files have been written to: C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/build

And then:

C:\Users\heiland\dev\RePhysiCell-cmake\RePhysiCell-cmake> cmake --build build
… (skip over warnings)
4 warnings generated.

[36/128] Building CXX object modules/CMakeFiles/PhysiCell-modules.dir/PhysiCell_settings.cpp.obj
FAILED: [code=1] modules/CMakeFiles/PhysiCell-modules.dir/PhysiCell_settings.cpp.obj
C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE   -march=native -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++20 -flto=thin -MD -MT modules/CMakeFiles/PhysiCell-modules.dir/PhysiCell_settings.cpp.obj -MF modules\CMakeFiles\PhysiCell-modules.dir\PhysiCell_settings.cpp.obj.d -o modules/CMakeFiles/PhysiCell-modules.dir/PhysiCell_settings.cpp.obj -c C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/modules/PhysiCell_settings.cpp
C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/modules/PhysiCell_settings.cpp:368:6: error: no member named 'create_directories' in namespace 'std::filesystem'; did you mean simply 'create_directories'?
  368 |         if (std::filesystem::create_directories(path, ec)) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |             create_directories
C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/modules/PhysiCell_settings.cpp:339:6: note: 'create_directories' declared here
  339 | bool create_directories(const std::string &path)
      |      ^
C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/modules/PhysiCell_settings.cpp:368:48: error: too many arguments to function call, expected single argument 'path', have 2 arguments
  368 |         if (std::filesystem::create_directories(path, ec)) {
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       ^~
C:/Users/heiland/dev/RePhysiCell-cmake/RePhysiCell-cmake/modules/PhysiCell_settings.cpp:339:6: note: 'create_directories' declared here
  339 | bool create_directories(const std::string &path)
      |      ^                  ~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
[41/128] Building CXX object modules/CMakeFiles/P...ell-modules-no-addon.dir/PhysiCell_pugixml.cpp.ob
ninja: build stopped: subcommand failed.

@asmelko
Copy link
Author

asmelko commented Oct 28, 2025

@rheiland Thanks a lot for being a testing dummy! :)

I don't recall having any issues with building an earlier PhysiCell release with cmake and cl, but could be mistaken. Just curious - what feature of OpenMP are we using that requires 5.0?

I am adding OpenMP >=4.0 requirement only for this kind of errors that we get when compiling with cl:

C:\Users\randy\git\adam_cmake\BioFVM\BioFVM_microenvironment.cpp(743,20): error C3016: 'i': 
index variable in OpenMP 'for' statement must have signed integral type

As my optimizations porting will be advancing, I may experiment with lowering the OpenMP version requirement and fixing some of these errors if it brings us interesting Windows portability.

Finally, I added a missing version include, now Windows build should compile. I added GitHub action to make sure of that.

@rheiland
Copy link
Collaborator

Using your latest code, I now get this and will try to find reasons/alternatives, but welcome comments:

C:\Users\heiland\dev\RePhysiCell-cmake>cmake -G Ninja -B build -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe"
-- The CXX compiler identification is Clang 21.1.4 with GNU-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (Required is at least version "4")
-- Could NOT find OpenMP (missing: OpenMP_CXX_FOUND) (Required is at least version "4")
CMake Warning at BioFVM/CMakeLists.txt:10 (message):
  OpenMP not found.  BioFVM will be built without OpenMP support.


-- Configuring done (11.0s)
-- Generating done (0.6s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_C_COMPILER


-- Build files have been written to: C:/Users/heiland/dev/RePhysiCell-cmake/build

@asmelko
Copy link
Author

asmelko commented Oct 30, 2025

@rheiland If you are referring to CMake Warning for unused variables, I would not bother by that too much. But if you mean a not found OpenMP support, that is concerning. I installed clang and LLVM toolset via visual studio installer and for me, OpenMP is found:

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\bin\clang.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\bin\clang.exe" --no-warn-unused-cli -S C:/Users/adams/Desktop/RePhysiCell -B c:/Users/adams/Desktop/RePhysiCell/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The CXX compiler identification is Clang 19.1.5 with GNU-like command-line
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/Llvm/bin/clang.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found OpenMP_CXX: -fopenmp=libomp (found suitable version "5.1", minimum required is "4")
[cmake] -- Found OpenMP: TRUE (found suitable version "5.1", minimum required is "4")
[cmake] -- Configuring done (4.3s)
[cmake] -- Generating done (0.4s)
[cmake] -- Build files have been written to: C:/Users/adams/Desktop/RePhysiCell/build

Maybe you also have a more behaving clang compiler version under BuildTools directory too?

@asmelko
Copy link
Author

asmelko commented Oct 31, 2025

Added GitHub actions for Building and Testing using CMake. Everything passes on Windows, MacOS, Ubuntu.

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.

3 participants