How do I get cmake to find the font size in a third party header mpi.h?

I am working on a free software project that includes HPC and the MPI library.

In my code, I need to know the size of the MPI_Offset type, which is defined in mpi.h.

Usually such projects will be built using autotools and this problem will be easily solved. But for my sins I am working with CMake build and I cannot find a way to accomplish this simple task. But there must be a way to do it - this is usually done on autotools projects, so I guess this is also possible in CMake.

When I use:

check_type_size("MPI_Offset" SIZEOF_MPI_OFFSET)

      

This fails because mpi.h is not in the generated C code.

Can I specify check_type_size () to include mpi.h?

+3


source to share


1 answer


This is done via CMAKE_EXTRA_INCLUDE_FILES

:

INCLUDE (CheckTypeSize) 

find_package(MPI)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})

SET(CMAKE_EXTRA_INCLUDE_FILES "mpi.h")
check_type_size("MPI_Offset" SIZEOF_MPI_OFFSET)
SET(CMAKE_EXTRA_INCLUDE_FILES)

      



It is perhaps more typical to write platform checks using autotools, so here's more information on how to write platform checks using CMake .

On a personal note, while CMake is definitely not the most enjoyable exercise, for me autotools is reserved for capital sins. I find it very difficult to protect CMake, but even documented in this case . Naturally setting a separate "variable" that you even have to reset after the fact rather than just passing it in as a parameter is clearly in line with CMake's amazing "design principles".

+2


source







All Articles