[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#943311: hyphy: please add pkg-config to Build-Depends for cross compilation



Source: hyphy
Version: 2.3.14+dfsg-2
Tags: patch
User: debian-cross@lists.debian.org
Usertags: ftcbfs

hyphy fails to cross build from source, because it fails finding mpi.
This happens, because cmake's FindMPI.cmake uses compiler wrappers such
as mpicc to discover mpi. Such compiler wrappers cannot work at all for
cross building and they will not be supported on Debian at all. Beyond
breaking cross compilation, compiler wrappers become a pain when you
need two of them (e.g. ccache/distcc/mpicc/...). As such they should be
avoided and the natural solution for this case is using pkg-config,
which is well-supported by all major mpi providers since ages.  Making
FindMPI.cmake use pkg-config is a separate issue outside the scope of
hyphy and there will be a separate bug about that. However, hyphy needs
to depend on pkg-config. Therefore, please add pkg-config to
Build-Depends. You can make this dependency conditional to cross
compilation by annotating it with <cross> if you like, because we'll
keep using mpicc for the native case. I don't think the unconditional
dependency hurts. Please consider applying the attached patch and
understand that it is only half of the picture: The required changes to
cmake are still to be filed. Applying this patch early will make it
easier to develop the cmake patch. I'm attaching my first draft for
reference only.

Helmut
diff --minimal -Nru hyphy-2.3.14+dfsg/debian/changelog hyphy-2.3.14+dfsg/debian/changelog
--- hyphy-2.3.14+dfsg/debian/changelog	2019-07-05 15:45:06.000000000 +0200
+++ hyphy-2.3.14+dfsg/debian/changelog	2019-10-23 09:00:30.000000000 +0200
@@ -1,3 +1,11 @@
+hyphy (2.3.14+dfsg-2.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Add pkg-config to Build-Depends as FindMPI.cmake will need it for cross
+    compilation. (Closes: #-1)
+
+ -- Helmut Grohne <helmut@subdivi.de>  Wed, 23 Oct 2019 09:00:30 +0200
+
 hyphy (2.3.14+dfsg-2) unstable; urgency=medium
 
   [ Saira Hussain ]
diff --minimal -Nru hyphy-2.3.14+dfsg/debian/control hyphy-2.3.14+dfsg/debian/control
--- hyphy-2.3.14+dfsg/debian/control	2019-07-05 15:45:06.000000000 +0200
+++ hyphy-2.3.14+dfsg/debian/control	2019-10-23 08:19:10.000000000 +0200
@@ -8,7 +8,8 @@
                mpi-default-dev,
                libcurl4-gnutls-dev | libcurl4-dev,
                libssl-dev,
-               libsqlite3-dev
+               libsqlite3-dev,
+               pkg-config,
 Standards-Version: 4.3.1
 Vcs-Browser: https://salsa.debian.org/med-team/hyphy
 Vcs-Git: https://salsa.debian.org/med-team/hyphy.git
--- cmake-3.13.4.orig/Modules/FindMPI.cmake
+++ cmake-3.13.4/Modules/FindMPI.cmake
@@ -247,6 +247,7 @@
 cmake_policy(SET CMP0057 NEW) # if IN_LIST
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPkgConfig.cmake)
 
 # Generic compiler names
 set(_MPI_C_GENERIC_COMPILER_NAMES          mpicc    mpcc      mpicc_r mpcc_r)
@@ -1459,7 +1460,40 @@
         if(NOT MPI_PINNED_COMPILER AND NOT MPI_${LANG}_WRAPPER_FOUND)
           # If MPI_PINNED_COMPILER wasn't given, and the MPI compiler we potentially found didn't work, we withdraw it.
           set(MPI_${LANG}_COMPILER "MPI_${LANG}_COMPILER-NOTFOUND" CACHE FILEPATH "MPI compiler for ${LANG}" FORCE)
-          if(NOT MPI_SKIP_GUESSING)
+
+          if(LANG STREQUAL "C")
+            set(_MPI_PKG "mpi-c")
+          elseif(LANG STREQUAL "CXX")
+            set(_MPI_PKG "mpi-cxx")
+          elseif(LANG STREQUAL "Fortran")
+            set(_MPI_PKG "mpi-fort")
+          else()
+            set(_MPI_PKG "")
+          endif()
+          if(_MPI_PKG)
+            pkg_check_modules("MPI_${LANG}_PKG" "${_MPI_PKG}")
+            if("${MPI_${LANG}_PKG_FOUND}")
+              set(MPI_${LANG}_COMPILE_OPTIONS  ${MPI_${LANG}_PKG_CFLAGS}        CACHE STRING "MPI ${LANG} compilation options"       FORCE)
+              set(MPI_${LANG}_INCLUDE_PATH     ${MPI_${LANG}_PKG_INCLUDE_DIRS}  CACHE STRING "MPI ${LANG} include directories"       FORCE)
+              set(MPI_${LANG}_LINK_FLAGS       ${MPI_${LANG}_PKG_LDFLAGS}       CACHE STRING "MPI ${LANG} linker flags"              FORCE)
+              set(MPI_${LANG}_LIB_NAMES        ${MPI_${LANG}_PKG_LIBRARIES}     CACHE STRING "MPI ${LANG} libraries to link against" FORCE)
+              foreach(_MPI_LIB IN LISTS MPI_${LANG}_LIB_NAMES)
+                if(_MPI_LIB)
+                  get_filename_component(_MPI_PLAIN_LIB_NAME "${_MPI_LIB}" NAME_WE)
+                  get_filename_component(_MPI_LIB_NAME "${_MPI_LIB}" NAME)
+                  get_filename_component(_MPI_LIB_DIR "${_MPI_LIB}" DIRECTORY)
+                  find_library(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY
+                    NAMES "${_MPI_LIB_NAME}" "lib${_MPI_LIB_NAME}"
+                    HINTS ${_MPI_LIB_DIR}
+                    DOC "Location of the ${_MPI_PLAIN_LIB_NAME} library for MPI"
+                  )
+                  mark_as_advanced(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY)
+                endif()
+              endforeach()
+            endif()
+          endif()
+
+          if(NOT MPI_SKIP_GUESSING AND NOT "${MPI_${LANG}_PKG_FOUND}")
             # For C++, we may use the settings for C. Should a given compiler wrapper for C++ not exist, but one for C does, we copy over the
             # settings for C. An MPI distribution that is in this situation would be IBM Platform MPI.
             if("${LANG}" STREQUAL "CXX" AND MPI_C_WRAPPER_FOUND)

Reply to: