blt icon indicating copy to clipboard operation
blt copied to clipboard

with newer cmake, use bonafide cmake targets for mpi and openmp

Open cyrush opened this issue 4 years ago • 1 comments

Are you tired of -pthead ruining your cuda linker's day?

Does -fopenmp come to your cuda parties uninvited?

Are you a library that doesn't even use cuda - but you still some how cause problems for your downstream friends (👎 ).

Great news! :

With newer cmake all of these things are solved by using the bonafide + standard cmake targets for these libs.

While BLT specific logic will be still needed for older cmake (my broad guess is cmake < 3.15 ), life is better with cmake's new and improved targets 🥇!

And life would be even better* if BLT moved to use them!

Here is an example of how we use these targets selectivity in one of our projects:

https://github.com/Alpine-DAV/ap_compositor/blob/5a6ca8030c26ae70fef0616b7e99c0796316176c/src/cmake/SetupBLT.cmake#L32

Finally, there are some things to think about with respect to exporting targets. We shouldn't have to export them and the import logic for packages should call find when necessary. That will make sure the bonafide targets are configured with proper language support depending on what is in play.

*Offer subject to details. Not valid for CMake versions less than 3.15.

cyrush avatar Sep 03 '21 15:09 cyrush

Without putting a lot of thought into this, here are two possible ideas on how to make this work in BLT with minimal changes in projects that use BLT today:

  1. Search and replace at runtime the BLT targets (mpi, openmp) in the DEPENDS_ON lists with the actual CMake targets (MPI::MPI_CXX, OpenMP::OpenMP_CXX). This has obvious downsides due to magic and the mpi and openmp targets wouldn't need to be exported/may not exist but projects would need to export or call findmpi.
  2. On newer CMake versions, create empty BLT targets and have them depend on their respective CMake targets. This again might cause confusion about what needs to be exported because projects would need to know to also export the other ones.

We might want to solve two problems at the same time. Convert over to newer CMake targets but also create a helper macro for exporting BLT targets. Something like:

blt_export_blt_targets(
    PREFIX myproject
    EXPORT_MPI ${MYPROJECT_ENABLE_MPI}
    EXPORT_OPENMP ${MYPROJECT_ENABLE_OPENMP})

This would allow us to hide any necessary exporting logic in a version tied BLT macro.

white238 avatar Sep 03 '21 16:09 white238