Skip to content

[CMake] Provide out-of-source build#768

Merged
landinjm merged 14 commits intoprisms-center:masterfrom
jijn:fix/outsourcebuild
Jan 20, 2026
Merged

[CMake] Provide out-of-source build#768
landinjm merged 14 commits intoprisms-center:masterfrom
jijn:fix/outsourcebuild

Conversation

@jijn
Copy link
Copy Markdown
Contributor

@jijn jijn commented Jan 8, 2026

Provide out-of-source build. This fixes #767.

$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src>
)
endforeach()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I fail to see why this section is needed. Aren't the includes already being added to path later down the line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The source code looks like:
#include <prismspf/core/conditional_ostreams.h>

The old one actually includes
${CMAKE_SOURCE_DIR}/include/prismspf/core/*.h

What you want to include is
${CMAKE_SOURCE_DIR}/include/

so it can find
prismspf/core/*.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead, can we add the following lines to cmake/macros/macro_define_library.cmake

target_include_directories(${_target} SYSTEM
  PRIVATE
  ${CMAKE_BINARY_DIR}/include
  ${CMAKE_SOURCE_DIR}/include 
  ${CMAKE_BINARY_DIR}/src
)

That should do the trick and prevent code duplication

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay, I can do this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tried this, got the error:

[ 38%] Building CXX object CMakeFiles/prisms_pf_debug.dir/src/core/constraint_handler.cc.o
/usr/bin/c++ -DBOOST_ATOMIC_DYN_LINK -DBOOST_ATOMIC_NO_LIB -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_IOSTREAMS_NO_LIB -DBOOST_SERIALIZATION_DYN_LINK -DBOOST_SERIALIZATION_NO_LIB -DBOOST_SYSTEM_DYN_LINK -DBOOST_SYSTEM_NO_LIB -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_NO_LIB -DDEBUG -D_GLIBCXX_ASSERTIONS -I/mnt/c/Users/xxx/phaseField/include -I/mnt/c/Users/xxx/phaseField/src -isystem /home/xxx/vtk-install/include/vtk-9.6 -isystem /home/xxx/dealii-candi/deal.II-v9.7.0/include -isystem /home/xxx/dealii-candi/deal.II-v9.7.0/include/deal.II/bundled -isystem /usr/lib/x86_64-linux-gnu/openmpi/include -isystem /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -isystem /usr/include/suitesparse -isystem /home/xxx/dealii-candi/hdf5-1.12.2/include -isystem /home/xxx/dealii-candi/p4est-2.3.6/FAST/include -std=c++20 -Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wuseless-cast -fopenmp-simd -march=native -O0 -ggdb -Wa,--compress-debug-sections -MD -MT CMakeFiles/prisms_pf_debug.dir/src/core/constraint_handler.cc.o -MF CMakeFiles/prisms_pf_debug.dir/src/core/constraint_handler.cc.o.d -o CMakeFiles/prisms_pf_debug.dir/src/core/constraint_handler.cc.o -c /mnt/c/Users/xxx/phaseField/src/core/constraint_handler.cc
/mnt/c/Users/xxx/phaseField/src/core/constraint_handler.cc:690:10: fatal error: core/constraint_handler.inst: No such file or directory
  690 | #include "core/constraint_handler.inst"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/prisms_pf_debug.dir/build.make:90: CMakeFiles/prisms_pf_debug.dir/src/core/constraint_handler.cc.o] Error 1
make[2]: Leaving directory '/mnt/c/Users/xxx/phaseField/build'
make[1]: *** [CMakeFiles/Makefile2:343: CMakeFiles/prisms_pf_debug.dir/all] Error 2
make[1]: Leaving directory '/mnt/c/Users/xxx/phaseField/build'
make: *** [Makefile:136: all] Error 2

It includes two folders

-I/mnt/c/Users/xxx/phaseField/include
-I/mnt/c/Users/xxx/phaseField/src

but it want to find
/build/src/core/constraint_handler.inst

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The issue has been resolved in the latest commit 9e29f6f

set_target_properties(
main-debug main-release
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we should include this in this PR. Out-of-source application builds are another topics

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can split it to a separate PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I suggest to include this. First, it won't affect current in-source build. Second, it is unnecessary to have a separate PR.

CMakeLists.txt Outdated
configure_file(
${CMAKE_SOURCE_DIR}/include/prismspf/config.h.in
${CMAKE_BINARY_DIR}/include/prismspf/config.h
${CMAKE_SOURCE_DIR}/include/prismspf/config.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can these two configure files calls be

configure_file(
		${CMAKE_CURRENT_SOURCE_DIR}/include/prismspf/config.h.in
		${CMAKE_CURRENT_BINARY_DIR}/include/prismspf/config.h
)

This will give them in the build directory as intended.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I now put "config.h" in the install directory instead of the build directory. In this case, we can completely separate the source/build directory from the install directory. Now we can build applications solely with the install directory.

else()
# We're in the main project context, use current binary dir
set(_main_build_dir ${CMAKE_BINARY_DIR})
set(_main_build_dir ${CMAKE_SOURCE_DIR})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't actually need to change this if we keep everything with respect to the binary dir

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe this impacts the application build, as it cannot locate headers within PRISMS_BINARY_DIR/include. That's why I moved config.h to the PRISMS source directory. If there is a way to expose PRISMS_BINARY_DIR to the application build, I am happy to revert this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I now move config.h to the install directory

@jijn
Copy link
Copy Markdown
Contributor Author

jijn commented Jan 13, 2026

What I did:

  • fix the code duplication problem, revert those changes in src/xxx/CmakeLists.txt
  • remove all dependency on files in the PRISMS source/build folder
  • I didn't remove the C dependency to make sure we can successfully build the applications. You can fix this in a separate PR.

Now we can compile applications solely rely on the installed library. You can delete the source code folder 'phaseField' completely without affecting the application build.

This is done by

  • clean the dependency on files in the source folder or the build folder
  • generate and put config.h to install_dir
  • copy VERSION to install_dir
  • copy cmake/ to install_dir
  • point all macros such as PRISMS_PF_SOURCE_DIR to install_dir

include files are now installed to install_dir/include/prismspf/xxx.h instead of install_dir/include/prismspf/prismspf/xxx.h

I didn't separate the out-of-source application builds, since it is wired that we cannot support both. This code wouldn't break current in-source build.

@landinjm landinjm self-requested a review January 14, 2026 19:08
@landinjm
Copy link
Copy Markdown
Contributor

Once merge conflicts are fixed this can be merged

@jijn
Copy link
Copy Markdown
Contributor Author

jijn commented Jan 19, 2026

The following commits should fix the application build error.

@landinjm landinjm added this pull request to the merge queue Jan 20, 2026
Merged via the queue into prisms-center:master with commit 2ecf611 Jan 20, 2026
3 checks passed
@jijn jijn deleted the fix/outsourcebuild branch February 7, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix build pipeline

3 participants