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

Fix CMake variables #178

Merged
merged 31 commits into from
May 30, 2024
Merged

Fix CMake variables #178

merged 31 commits into from
May 30, 2024

Conversation

dutkalex
Copy link
Contributor

No description provided.

@dutkalex dutkalex marked this pull request as draft April 25, 2024 09:34
@dutkalex dutkalex marked this pull request as ready for review April 25, 2024 12:45
@cburstedde
Copy link
Owner

Thanks! Unifying the variables is great. Would you mind adding a file doc/author_.txt like the others, releasing your code under the FreeBSD license? And if you could add a line to doc/release_notes.txt?

(Wondering why all of a sudden the autotools ./bootstrap script dies on Darwin (unrelated).)

Any comments @scivision -- thinking about callability from other software besides p4est.

@dutkalex
Copy link
Contributor Author

Done! @cburstedde

@tim-griesbach
Copy link
Collaborator

Thanks for the simplifications!

We tried out the changes and setting SC_USE_INTERNAL_ZLIB in ccmake to ON leads to the following configure error:

 CMake Error at cmake/zlib.cmake:60 (add_library):
   add_library cannot create imported target "ZLIB::ZLIB" because another
   target with the same name already exists.
 Call Stack (most recent call first):
   cmake/config.cmake:36 (include)
   CMakeLists.txt:15 (include)

cc @hannesbrandt

@dutkalex
Copy link
Contributor Author

@tim-griesbach @hannesbrandt Thanks for letting me know. This should work better now :)

@cburstedde
Copy link
Owner

cburstedde commented Apr 30, 2024 via email

@tim-griesbach
Copy link
Collaborator

@tim-griesbach @hannesbrandt Thanks for letting me know. This should work better now :)

Thank you for the quick response!
We tried out your recent changes and we get

-- Build files have been written to: /home/griesbac/workspace/sc_cmake/ZLIB-prefix/src/ZLIB-build
[ 10%] Performing build step for 'ZLIB'
[100%] Built target zlib
[ 11%] Performing install step for 'ZLIB'
[100%] Built target zlib
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libz.a
CMake Error at cmake_install.cmake:46 (file):
  file INSTALL cannot copy file
  "/home/griesbac/workspace/sc_cmake/ZLIB-prefix/src/ZLIB-build/libz.a" to
  "/usr/local/lib/libz.a": Permission denied.

Without the changes of this PR, we obtained

-- Build files have been written to: /home/griesbac/workspace/sc_cmake/ZLIB-prefix/src/ZLIB-build
[ 10%] Performing build step for 'ZLIB'
[100%] Built target zlib
[ 11%] Performing install step for 'ZLIB'
[100%] Built target zlib
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/lib/libz.a
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/include/zlib.h
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/include/zlib_name_mangling.h
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/include/zconf.h
-- Installing: /home/griesbac/workspace/sc_cmake/local/lib/pkgconfig/zlib.pc
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/lib/libz.a
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/lib/cmake/ZLIB/ZLIB.cmake
-- Installing: /home/griesbac/workspace/sc_cmake/local/lib/cmake/ZLIB/ZLIB-release.cmake
[ 13%] Completed 'ZLIB'

Apparently the installation directory of zlib changed to a path outside of the build directory.

@tim-griesbach
Copy link
Collaborator

We saw that when one is initially calling cmake without any passed options and then calls ccmake to switch SC_ENABLE_MPI to ON, one gets the warning that MPI I/O is disabled/not found. However, an initial call of cmake with the command line parameter -DSC_ENABLE_MPI=1 works fine.

We tested also the code without the changes of this PR and copied the moved warnings to the same place as in this PR but the code still did not show the warning.

@tim-griesbach
Copy link
Collaborator

In the long run, it seems that namespace cleanliness would win, so we will go for the SC_ENABLE_* variables. Is there no way at all to have a short CMake setting via "mpi", maybe with presets, on the command/configure line?

After some further tinkering, we found a possible way. One could add

if (DEFINED mpi)
  set (SC_ENABLE_MPI ${mpi} CACHE BOOL "" FORCE)
endif()

directly before the first appearance of SC_ENABLE_MPI in cmake/config.cmake. While mpi does not show up in ccmake, it is still possible to use -Dmpi.

@dutkalex
Copy link
Contributor Author

Thank you for the quick response! We tried out your recent changes and we get

-- Build files have been written to: /home/griesbac/workspace/sc_cmake/ZLIB-prefix/src/ZLIB-build
[ 10%] Performing build step for 'ZLIB'
[100%] Built target zlib
[ 11%] Performing install step for 'ZLIB'
[100%] Built target zlib
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libz.a
CMake Error at cmake_install.cmake:46 (file):
  file INSTALL cannot copy file
  "/home/griesbac/workspace/sc_cmake/ZLIB-prefix/src/ZLIB-build/libz.a" to
  "/usr/local/lib/libz.a": Permission denied.

Without the changes of this PR, we obtained

-- Build files have been written to: /home/griesbac/workspace/sc_cmake/ZLIB-prefix/src/ZLIB-build
[ 10%] Performing build step for 'ZLIB'
[100%] Built target zlib
[ 11%] Performing install step for 'ZLIB'
[100%] Built target zlib
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/lib/libz.a
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/include/zlib.h
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/include/zlib_name_mangling.h
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/include/zconf.h
-- Installing: /home/griesbac/workspace/sc_cmake/local/lib/pkgconfig/zlib.pc
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/lib/libz.a
-- Up-to-date: /home/griesbac/workspace/sc_cmake/local/lib/cmake/ZLIB/ZLIB.cmake
-- Installing: /home/griesbac/workspace/sc_cmake/local/lib/cmake/ZLIB/ZLIB-release.cmake
[ 13%] Completed 'ZLIB'

Apparently the installation directory of zlib changed to a path outside of the build directory.

Yes this is intentional. Hardcoding the install path into the CMakeLists.txt is a code smell. The install path is meant to be set on the command line as it depends on the target machine. Enforcing one breaks portability, composability with downstream software, and packaging tools such as CPack or Spack. In order to retrieve the old behavior you just need to specify it with a -DCMAKE_INSTALL_PREFIX=... or using the --prefix option of cmake.

@dutkalex
Copy link
Contributor Author

We saw that when one is initially calling cmake without any passed options and then calls ccmake to switch SC_ENABLE_MPI to ON, one gets the warning that MPI I/O is disabled/not found. However, an initial call of cmake with the command line parameter -DSC_ENABLE_MPI=1 works fine.

We tested also the code without the changes of this PR and copied the moved warnings to the same place as in this PR but the code still did not show the warning.

Very strange behavior. Maybe some cache issue...
Let me investigate and get back to you...

@dutkalex
Copy link
Contributor Author

In the long run, it seems that namespace cleanliness would win, so we will go for the SC_ENABLE_* variables. Is there no way at all to have a short CMake setting via "mpi", maybe with presets, on the command/configure line?

After some further tinkering, we found a possible way. One could add

if (DEFINED mpi)
  set (SC_ENABLE_MPI ${mpi} CACHE BOOL "" FORCE)
endif()

directly before the first appearance of SC_ENABLE_MPI in cmake/config.cmake. While mpi does not show up in ccmake, it is still possible to use -Dmpi.

Yes this seems like a good tradeoff: existing code would continue working, but new downstream projects would not notice it. I can include it in the PR if this is ok for everyone

@dutkalex
Copy link
Contributor Author

dutkalex commented Apr 30, 2024

Is there no way at all to have a short CMake setting via "mpi", maybe with presets, on the command/configure line?

Hardcoding the install path into the CMakeLists.txt is a code smell.

@cburstedde @tim-griesbach Another solution to both of these problems could be to define a custom SCDev (or whatever) build mode which provides the desired defaults and shortcuts...

doc/author_dutka.txt Outdated Show resolved Hide resolved
@cburstedde
Copy link
Owner

Wondering about the CI in that one instance... and thanks for adding the mpi and debug shortcuts.

@dutkalex
Copy link
Contributor Author

Ah yes right! Thanks for reminding me! Last time I could not reproduce the issue but I'll give it another try

I finally managed to replicate the problem. I don't quite understand what was the root cause, but it should be fixed now!

@tim-griesbach
Copy link
Collaborator

Ah yes right! Thanks for reminding me! Last time I could not reproduce the issue but I'll give it another try

I finally managed to replicate the problem. I don't quite understand what was the root cause, but it should be fixed now!

Thank you for the fix! I tried out your changes and it works for me as well.

@cburstedde cburstedde mentioned this pull request May 16, 2024
@cburstedde
Copy link
Owner

Wondering about the CI in that one instance... and thanks for adding the mpi and debug shortcuts.

This may be resolved after the latest merge into develop.

@cburstedde
Copy link
Owner

So close. What's going on on Windows now (unrelated?)?

@dutkalex
Copy link
Contributor Author

I think so:

CMake Error at C:/Program Files/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find MPI (missing: MPI_C_FOUND C)

@cburstedde
Copy link
Owner

CMake Error at C:/Program Files/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find MPI (missing: MPI_C_FOUND C)

Thanks; I'd think @scivision would know how to repair this.

@scivision
Copy link
Contributor

scivision commented May 20, 2024

There was conflicting CMake variable use, fixed by this patch

178.patch

Note that CMAKE_BUILD_TYPE must be set before project() or it has no effect.

@cburstedde
Copy link
Owner

There was conflicting CMake variable use, fixed by this patch

178.patch

Note that CMAKE_BUILD_TYPE must be set before project() or it has no effect.

Thanks; when I keep using -Dmpi the error persists. The most recent code has the purpose to allow for -Dmpi on the cmake command line while using SC_ENABLE_MPI as the variable that is used in the cmake code. Is there a way to make this work with cmake -Dmpi?

@cburstedde
Copy link
Owner

Ok I've integrated it all with the latest develop version. Sorry for the merge in between. It got a bit confusing, but at least we're current with everything.

Would @dutkalex check whether this is all correct and I didn't screw up the merge?

@dutkalex
Copy link
Contributor Author

Looks good to me @cburstedde 😊

@cburstedde
Copy link
Owner

Welcome to the developer list. :)

@cburstedde cburstedde merged commit 3a00a6a into cburstedde:develop May 30, 2024
36 checks passed
@dutkalex dutkalex deleted the cmake-fix branch May 30, 2024 14:05
@elykwilliams
Copy link
Contributor

@dutkalex Can you please restore your branch, it seems one of your commits has broken the CI.

@dutkalex dutkalex restored the cmake-fix branch May 31, 2024 06:27
@cburstedde
Copy link
Owner

cburstedde commented May 31, 2024 via email

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.

5 participants