[CMake] Provide out-of-source build#768
Conversation
| $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src> | ||
| ) | ||
| endforeach() | ||
|
|
There was a problem hiding this comment.
I fail to see why this section is needed. Aren't the includes already being added to path later down the line?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
The issue has been resolved in the latest commit 9e29f6f
| set_target_properties( | ||
| main-debug main-release | ||
| PROPERTIES | ||
| RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR} |
There was a problem hiding this comment.
I don't think we should include this in this PR. Out-of-source application builds are another topics
There was a problem hiding this comment.
I can split it to a separate PR
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}) |
There was a problem hiding this comment.
We don't actually need to change this if we keep everything with respect to the binary dir
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I now move config.h to the install directory
|
What I did:
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
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. |
|
Once merge conflicts are fixed this can be merged |
|
The following commits should fix the application build error. |
Provide out-of-source build. This fixes #767.