From patchwork Thu Oct 27 23:06:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9400637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07931605EE for ; Thu, 27 Oct 2016 23:06:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1D4D2A1B7 for ; Thu, 27 Oct 2016 23:06:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D68DF2A360; Thu, 27 Oct 2016 23:06:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD1FD2A354 for ; Thu, 27 Oct 2016 23:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933403AbcJ0XGP (ORCPT ); Thu, 27 Oct 2016 19:06:15 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:60241 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030400AbcJ0XGO (ORCPT ); Thu, 27 Oct 2016 19:06:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=References:In-Reply-To:Message-Id:Date:Subject:To:From; bh=TI4H2FKV840Y1AzpfzmLUxUwj4L3e76e7s6Gcutnhe0=; b=cUnmt8XHQEtxyk+GlnooarDkK/xc193W67Y+39aQ5bjbmlAeXkH7DTUxpSlBgGLnUrqASndXYrgOP+6mVpnzPgi3I0Gw93MBVoyTDZnaYuQkP7H9KsUX50wLJDhwcKVARlAzVO4HRRv4V9bQ1ZYUeSyqlg6+64UNHU+OlYz1kYI=; Received: from [10.0.0.151] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bztkS-0007gf-8Y; Thu, 27 Oct 2016 17:06:12 -0600 From: Jason Gunthorpe To: Doug Ledford , linux-rdma@vger.kernel.org Subject: [PATCH rdma-core 1/4] Support -DKERNEL_DIR to use kernel UAPI headers directly Date: Thu, 27 Oct 2016 17:06:07 -0600 Message-Id: <1477609570-8087-2-git-send-email-jgunthorpe@obsidianresearch.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1477609570-8087-1-git-send-email-jgunthorpe@obsidianresearch.com> References: <1477609570-8087-1-git-send-email-jgunthorpe@obsidianresearch.com> X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is useful to painlessly test if the kernel headers work with the build. All the kernel header shimming is moved into buildlib/RDMA_LinuxHeaders.cmake, new headers can be added to the list. Signed-off-by: Jason Gunthorpe --- CMakeLists.txt | 11 ++---- buildlib/RDMA_LinuxHeaders.cmake | 85 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 buildlib/RDMA_LinuxHeaders.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 230aab5ee01f..7abaa895c173 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ # Produce static libraries along with the usual shared libraries. # -DVERBS_PROVIDER_DIR='' (default /usr/lib.../libibverbs) # Use the historical search path for providers, in the standard system library. +# -DKERNEL_DIR='.../linux' (default '') +# If set use the kernel UAPI headers from this kernel source tree. cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) project(RDMA C) @@ -241,10 +243,7 @@ endif() # should rely on this. check_type_size("long" SIZEOF_LONG BUILTIN_TYPES_ONLY LANGUAGE C) -# Are our kernel headers new enough? -# If not replace them with built-in copies so we can continue to build. -CHECK_INCLUDE_FILE("rdma/rdma_user_rxe.h" HAVE_RDMA_USER_RXE) -RDMA_DoFixup("${HAVE_RDMA_USER_RXE}" "rdma/rdma_user_rxe.h") +include(RDMA_LinuxHeaders) #------------------------- # Apply fixups @@ -375,9 +374,7 @@ else() message(STATUS " netlink/route/link.h and net/if.h NOT co-includable (old headers)") endif() endif() -if (NOT HAVE_RDMA_USER_RXE) - message(STATUS " rdma/rdma_user_rxe.h NOT found (old system kernel headers)") -endif() +rdma_report_missing_kheaders() if (NOT HAVE_C_WARNINGS) message(STATUS " extended C warnings NOT supported") endif() diff --git a/buildlib/RDMA_LinuxHeaders.cmake b/buildlib/RDMA_LinuxHeaders.cmake new file mode 100644 index 000000000000..bd16d8deca72 --- /dev/null +++ b/buildlib/RDMA_LinuxHeaders.cmake @@ -0,0 +1,85 @@ +# COPYRIGHT (c) 2016 Obsidian Research Corporation. See COPYING file + +# Check that the system kernel headers are new enough, if not replace the +# headers with our internal copy. + +set(DEFAULT_TEST "int main(int argc,const char *argv[]) {return 1;}") +set(MISSING_HEADERS "") + +function(rdma_canon_header PATH OUT_VAR) + string(TOUPPER "${PATH}" HAVE) + string(REPLACE " " "_" HAVE "${HAVE}") + string(REPLACE "/" "_" HAVE "${HAVE}") + string(REPLACE "." "_" HAVE "${HAVE}") + set("${OUT_VAR}" "HAVE_${HAVE}" PARENT_SCOPE) +endfunction() + +function(rdma_check_kheader PATH C_TEST) + rdma_canon_header("${PATH}" HAVE) + + if(KERNEL_DIR) + # Drop a symlink back to the kernel into our include/ directory + if (EXISTS "${KERNEL_DIR}/include/uapi/${PATH}") + set(DEST "${BUILD_INCLUDE}/${PATH}") + + if(CMAKE_VERSION VERSION_LESS "2.8.12") + get_filename_component(DIR ${DEST} PATH) + else() + get_filename_component(DIR ${DEST} DIRECTORY) + endif() + file(MAKE_DIRECTORY "${DIR}") + + # We cannot just -I the kernel UAPI dir, it depends on some + # post-processing of things like linux/stddef.h. Instead we symlink the + # kernel headers into our tree and rely on the distro's fixup of + # non-rdma headers. The RDMA headers are all compatible with this + # scheme. + execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" + "${KERNEL_DIR}/include/uapi/${PATH}" + "${DEST}") + else() + message(FATAL_ERROR "Kernel tree does not contain expected UAPI header" + "${KERNEL_DIR}/include/uapi/${PATH}") + endif() + + set(CMAKE_REQUIRED_INCLUDES "${BUILD_INCLUDE}") + endif() + + # Note: The RDMA kernel headers use sockaddr{_in,_in6,}/etc so we have to + # include system headers to define sockaddrs before testing any of them. + CHECK_C_SOURCE_COMPILES(" + #include + #include + #include <${PATH}> +${C_TEST}" "${HAVE}") + + if(KERNEL_DIR) + if (NOT "${${HAVE}}") + # Run the compile test against the linked kernel header, this is to help + # make sure the compile tests work before the headers hit the distro + message(FATAL_ERROR "Kernel UAPI header failed compile test" + "${PATH}") + endif() + else() + RDMA_DoFixup("${${HAVE}}" "${PATH}") + if (NOT "${${HAVE}}") + list(APPEND MISSING_HEADERS "${PATH}") + set(MISSING_HEADERS "${MISSING_HEADERS}" PARENT_SCOPE) + endif() + endif() +endfunction() + +function(rdma_report_missing_kheaders) + foreach(I IN LISTS MISSING_HEADERS) + message(STATUS " ${I} NOT found (old system kernel headers)") + endforeach() +endfunction() + +# This list is topologically sorted +rdma_check_kheader("rdma/ib_user_verbs.h" "${DEFAULT_TEST}") +rdma_check_kheader("rdma/ib_user_sa.h" "${DEFAULT_TEST}") +rdma_check_kheader("rdma/ib_user_cm.h" "${DEFAULT_TEST}") +rdma_check_kheader("rdma/ib_user_mad.h" "${DEFAULT_TEST}") +rdma_check_kheader("rdma/rdma_netlink.h" "${DEFAULT_TEST}") +rdma_check_kheader("rdma/rdma_user_cm.h" "${DEFAULT_TEST}") +rdma_check_kheader("rdma/rdma_user_rxe.h" "${DEFAULT_TEST}")