Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't seem to set up a top level CMakeLists.txt for the entire code gallery #133

Open
bangerth opened this issue Apr 11, 2023 · 4 comments

Comments

@bangerth
Copy link
Member

This might need @tamiko 's input:

I've gotten tired of configuring and compiling each code gallery program individually, so I tried to set up this CMakeLists.txt file in the top level of the code gallery:

cmake_minimum_required(VERSION 3.13.4)
project(code-gallery)

add_subdirectory(advection_reaction_estimator)

Interestingly, this does not work. When I create a build directory and call cmake .. from there, the output is the following:

-- The CXX compiler identification is GNU 4.8.5
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - broken
CMake Error at /raid/bangerth/bin/share/cmake-3.20/Modules/CMakeTestCXXCompiler.cmake:59 (message):
  The C++ compiler

    "/usr/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/fac/g/bangerth/p/deal.II/1/code-gallery/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_f0d54/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_f0d54.dir/build.make CMakeFiles/cmTC_f0d54.dir/build
    gmake[1]: Entering directory `/raid/bangerth/p/deal.II/1/code-gallery/build/CMakeFiles/CMakeTmp'
    gmake[1]: Warning: File `CMakeFiles/cmTC_f0d54.dir/progress.make' has modification time 0.0017 s in the future
    Building CXX object CMakeFiles/cmTC_f0d54.dir/testCXXCompiler.cxx.o
    /usr/bin/c++   -std=c++20  -o CMakeFiles/cmTC_f0d54.dir/testCXXCompiler.cxx.o -c /home/fac/g/bangerth/p/deal.II/1/code-gallery/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    c++: error: unrecognized command line option ‘-std=c++20’
    gmake[1]: *** [CMakeFiles/cmTC_f0d54.dir/testCXXCompiler.cxx.o] Error 1
    gmake[1]: Leaving directory `/raid/bangerth/p/deal.II/1/code-gallery/build/CMakeFiles/CMakeTmp'
    gmake: *** [cmTC_f0d54/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:8 (project)


-- Configuring incomplete, errors occurred!

That is, it errors out while trying to identify a C++ compiler, which it takes from /usr/bin, but this is not the one I want it to use nor the one it should find via my $PATH:

 which c++
/scratch/local/gcc-11.2.0/bin/c++

It is also not the one it should inherit from the deal.II configuration system. (The specific error you see above is because I do `export CXXFLAGS=-std=c++20 which the system compiler predictably does not understand, it being GCC 4.8.)

Curiously, if I call cmake from the subdirectory into which I asked cmake to recurse (namely, advection_reaction_estimator), then this all works:

code-gallery/build> cd ../advection_reaction_estimator/
reaction_estimator> cmake .
-- The CXX compiler identification is GNU 11.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /scratch/local/gcc-11.2.0/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using the deal.II-9.5.0-pre installation found at /home/fac/g/bangerth/p/deal.II/1/install
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_deal_ii_add_test.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_deal_ii_initialize_cached_variables.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_deal_ii_invoke_autopilot.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_deal_ii_pickup_tests.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_deal_ii_query_git_information.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_deal_ii_setup_target.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_shell_escape_option_groups.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_target_compile_flags.cmake
-- Include macro /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_target_link_flags.cmake
###
#
#  WARNING:
#
#  CMAKE_BUILD_TYPE "" unsupported by current installation!
#  deal.II was configured with "DebugRelease".
#
#  CMAKE_BUILD_TYPE was forced to "Debug".
#
###
-- The C compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /scratch/local/gcc-11.2.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Autopilot invoked
###
#
#  Project  DG_advection_reaction_estimator  set up with  deal.II-9.5.0-pre  found at
#      /home/fac/g/bangerth/p/deal.II/1/install
#
#  CMAKE_BUILD_TYPE:          Debug
#
#  You can now run
#       $ make                - to compile and link the program
#       $ make run            - to (compile, link and) run the program
#
#       $ make debug          - to switch the build type to 'Debug'
#       $ make release        - to switch the build type to 'Release'
#
#       $ make edit_cache     - to change (cached) configuration variables
#                               and rerun the configure and generate phases of CMake
#
#       $ make strip_comments - to strip the source files in this
#                               directory off their comments; this is irreversible
#       $ make clean          - to remove the generated executable as well as
#                               all intermediate compilation files
#       $ make runclean       - to remove all output generated by the program
#       $ make distclean      - to clean the directory from _all_ generated
#                               files (includes clean, runclean and the removal
#                               of the generated build system)
#       $ make info           - to view this message again
#
#  Have a nice day!
#
###
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fac/g/bangerth/p/deal.II/1/code-gallery/advection_reaction_estimator

How do we make this work? Or is setting up multiple deal.II-based projects at once just not supported?

@masterleinad
Copy link
Member

I wouldn't expect in a CMake project that the compiler is inferred from any of the dependencies and specifying the compiler explicitly should still work. I am getting

$ cmake -DCMAKE_CXX_COMPILER=clang++ -DDEAL_II_DIR=~/Software/dealii-install/ ..
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is Clang 15.0.7
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/homebrew/Cellar/llvm/15.0.7_1/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using the deal.II-9.5.0-pre installation found at /Users/darndt/Software/dealii-install
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_deal_ii_add_test.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_deal_ii_initialize_cached_variables.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_deal_ii_invoke_autopilot.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_deal_ii_pickup_tests.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_deal_ii_query_git_information.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_deal_ii_setup_target.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_shell_escape_option_groups.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_target_compile_flags.cmake
-- Include macro /Users/darndt/Software/dealii-install/share/deal.II/macros/macro_target_link_flags.cmake
###
#
#  WARNING:
#
#  CMAKE_BUILD_TYPE "" unsupported by current installation!
#  deal.II was configured with "DebugRelease".
#
#  CMAKE_BUILD_TYPE was forced to "Debug".
#
###
-- Autopilot invoked
###
#
#  Project  DG_advection_reaction_estimator  set up with  deal.II-9.5.0-pre  found at
#      /Users/darndt/Software/dealii-install
#
#  CMAKE_BUILD_TYPE:          Debug
#
#  You can now run
#       $ make                - to compile and link the program
#       $ make run            - to (compile, link and) run the program
#
#       $ make sign           - to sign the executable with the supplied OSX developer key
#
#       $ make debug          - to switch the build type to 'Debug'
#       $ make release        - to switch the build type to 'Release'
#
#       $ make edit_cache     - to change (cached) configuration variables
#                               and rerun the configure and generate phases of CMake
#
#       $ make strip_comments - to strip the source files in this
#                               directory off their comments; this is irreversible
#       $ make clean          - to remove the generated executable as well as
#                               all intermediate compilation files
#       $ make runclean       - to remove all output generated by the program
#       $ make distclean      - to clean the directory from _all_ generated
#                               files (includes clean, runclean and the removal
#                               of the generated build system)
#       $ make info           - to view this message again
#
#  Have a nice day!
#
###
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/darndt/Software/dealii-code-gallery/build

@bangerth
Copy link
Member Author

Ah, interesting. Using -DCMAKE_CXX_COMPILER actually works -- though it's not clear to me because I don't have to do that when configuring the individual code gallery programs, nor when configuring deal.II. It just gets the compiler from $PATH.

Anyway, the next problem we run into is then this:

CMake Error at /home/fac/g/bangerth/p/deal.II/1/install/share/deal.II/macros/macro_deal_ii_invoke_autopilot.cmake:89 (add_custom_target):
  add_custom_target cannot create target "run" because another target with
  the same name already exists.  The existing target is a custom target
  created in source directory
  "/home/fac/g/bangerth/p/deal.II/1/code-gallery/advection_reaction_estimator".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  NavierStokes_TRBDF2_DG/CMakeLists.txt:54 (DEAL_II_INVOKE_AUTOPILOT)

and many more of the same kind.

@masterleinad
Copy link
Member

Right. This would work better if we were to use a more CMake-native approach again. 🙂
Something like

diff --git a/advection_reaction_estimator/CMakeLists.txt b/advection_reaction_estimator/CMakeLists.txt
index 826f55b..3091738 100644
--- a/advection_reaction_estimator/CMakeLists.txt
+++ b/advection_reaction_estimator/CMakeLists.txt
@@ -23,6 +23,5 @@ IF(NOT ${deal.II_FOUND})
     )
 ENDIF()
 
-DEAL_II_INITIALIZE_CACHED_VARIABLES()
-PROJECT(${TARGET})
-DEAL_II_INVOKE_AUTOPILOT()
+ADD_EXECUTABLE(${TARGET} ${TARGET_SRC})
+TARGET_LINK_LIBRARIES(${TARGET} dealii::dealii)

@bangerth
Copy link
Member Author

Yes. Once @tamiko has this all in a stable state, that's what we may want to do with the tutorials first, and then also the code gallery...

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

No branches or pull requests

2 participants