Skip to content

Commit

Permalink
Unified CMake build system
Browse files Browse the repository at this point in the history
This replaces the various autoconf/automake/libtool based schemes
unified cmake based scheme.

At this commit both schemes exist in the tree and can be run concurrently.
Except for the differences noted below they produce identical
'make install' and identical intput to cpp. This commit is intended
to be nearly 'no change' in terms of building.

An analysis of the post-install result shows the following differences:
 - cmake makes shlib symlinks libX.so -> libX.so.1 -> libX.so.1.0.0, while
   libtool does libX.so -> libX.so.1.0.0
 - librspreload's non-link name is lib/rsocket/librspreload.so (not .so.1)
   This correctly reflects the fact it is a soname-less LD_PRELOAD library.
   Symlinks are maintained for the other two incorrect names.
 - No static version of librspreload is produced. This library is only
   useful for LD_PRELOAD and cannot be statically linked to.
 - The provider shared library plugins and the LD_PRELOAD library
   have no SONAME. This is standard for plugin libraries.
 - The plugin shared libraries are not marked executable
 - -std=gnu99 is turned on globally
 - All shlibs have correct shared library dependencies (--as-needed and
   --no-undefined are turned on).
   Several binaries drop their pthreads dependency as they don't use it.
 - NDEBUG is controlled globally.
   Previously only libcxgb4 explicitly defined it
   Distros force this to be set during package built so this is no
   change
 - libtool *.la files are produced by cmake since libtool is not used
   and have a few minor differences:
   - Providers do not list the 'libX.so' bogus name, the .so is called
     libX-rdmav2.so
   - version information (current/age/revision) is bogus
   - The .la files are not marked executable

Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
jgunthorpe committed Sep 21, 2016
1 parent f2e0dd3 commit 8d4ebd8
Show file tree
Hide file tree
Showing 44 changed files with 1,901 additions and 0 deletions.
293 changes: 293 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
# COPYRIGHT (c) 2016 Obsidian Research Corporation. See COPYING file
# Run cmake as:
# mkdir build
# cmake -GNinja ..
# ninja
#
# Common options passed to cmake are:
# -DCMAKE_EXPORT_COMPILE_COMMANDS=1
# Write a compile_commands.json file for clang tooling
# -DENABLE_VALGRIND=1 (default disabled)
# Embed valgrind notations, this has a tiny negative performance impact
# -DENABLE_RESOLVE_NEIGH=0 (default enabled)
# Do not link to libnl and do not resolve neighbours internally for Ethernet,
# and do not build iwpmd.

cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(RDMA C)

# CMake likes to use -rdynamic too much, they fixed it in 3.4.
if(POLICY CMP0065)
cmake_policy(SET CMP0065 NEW)
else()
# .. but we really do want to opt out.
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
endif()

set(PACKAGE_NAME "RDMA")
# FIXME versioning strategy?
set(PACKAGE_VERSION "1")

#-------------------------
# Basic standard paths
include(GNUInstallDirs)
# C include root
set(BUILD_INCLUDE ${CMAKE_BINARY_DIR}/include)
# Executables
set(BUILD_BIN ${CMAKE_BINARY_DIR}/bin)
# Libraries
set(BUILD_LIB ${CMAKE_BINARY_DIR}/lib)

# Location to place provider .driver files
set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/libibverbs.d")
set(CMAKE_INSTALL_INITDDIR "${CMAKE_INSTALL_SYSCONFDIR}/init.d"
CACHE PATH "Location for init.d files")
set(CMAKE_INSTALL_SYSTEMD_SERVICEDIR "${CMAKE_INSTALL_PREFIX}/lib/systemd"
CACHE PATH "Location for systemd service files")

set(ACM_PROVIDER_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/ibacm"
CACHE PATH "Location for ibacm provider plugin shared library files.")

#-------------------------
# Load CMake components
set(BUILDLIB "${CMAKE_SOURCE_DIR}/buildlib")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BUILDLIB}")

include(FindPkgConfig)
include(CheckCCompilerFlag)
include(CheckIncludeFile)
include(CheckTypeSize)
include(RDMA_EnableCStd)
include(RDMA_DoFixup)
include(publish_headers)
include(rdma_functions)

#-------------------------
# Setup the basic C compiler
include_directories(${BUILD_INCLUDE})
# FIXME: Eliminate HAVE_CONFIG_H, we always have it.
add_definitions(-DHAVE_CONFIG_H)

# Require GNU99 mode
RDMA_EnableCStd()

# Extra warnings. Turn on -Wextra to keep aware of interesting developments from gcc,
# but turn off some that are not terribly useful for this source.
# FIXME: I wonder how many of the signed compares are bugs?
RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WARNINGS
"-Wall -Wextra -Wno-sign-compare -Wno-unused-parameter")

# At some point around 5.4 gcc fixed missing-field-initializers to ignore this
# common idiom we use extensively. Since this is a useful warning for
# developers try and leave it on if the compiler supports it.
CHECK_C_SOURCE_COMPILES("
struct foo { int a; int b; };
int main(int argc,const char *argv[]) { struct foo tmp = {}; return tmp.a; }"
HAVE_C_WORKING_MISSING_FIELD_INITIALIZERS
FAIL_REGEX "warning")
if (NOT HAVE_C_WORKING_MISSING_FIELD_INITIALIZERS)
RDMA_AddOptCFlag(CMAKE_C_FLAGS HAVE_C_WNO_MISSING_FIELD_INITIALIZERS "-Wno-missing-field-initializers")
endif()

# Check that the compiler supports -fno-strict-aliasing.
# The use of this flag in the source is discouraged
set(NO_STRICT_ALIASING_FLAGS "")
RDMA_AddOptCFlag(NO_STRICT_ALIASING_FLAGS HAVE_NO_STRICT_ALIASING
"-fno-strict-aliasing")

# The code does not do the racy fcntl if the various CLOEXEC's are not
# supported so it really doesn't work right if this isn't available. Thus hard
# require it.
CHECK_C_SOURCE_COMPILES("
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <fcntl.h>
int main(int argc,const char *argv[]) {
open(\".\",O_RDONLY | O_CLOEXEC);
socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
return 0;
}" HAS_CLOEXEC)
if (NOT HAS_CLOEXEC)
message(FATAL_ERROR "O_CLOEXEC/SOCK_CLOEXEC/fopen(..,\"e\") support is required but not found")
endif()

# always_inline is supported
CHECK_C_SOURCE_COMPILES("
inline __attribute__((always_inline)) int foo(void) {return 0;}
int main(int argc,const char *argv[]) { return foo(); }"
HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE
FAIL_REGEX "warning")

# Enable development support features
# Prune unneeded shared libraries during linking
RDMA_AddOptCFlag(CMAKE_EXE_LINKER_FLAGS SUPPORTS_AS_NEEDED "-Wl,--as-needed")
RDMA_AddOptCFlag(CMAKE_SHARED_LINKER_FLAGS SUPPORTS_AS_NEEDED "-Wl,--as-needed")
RDMA_AddOptCFlag(CMAKE_MODULE_LINKER_FLAGS SUPPORTS_AS_NEEDED "-Wl,--as-needed")

# Ensure all shared ELFs have fully described linking
RDMA_AddOptCFlag(CMAKE_EXE_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-Wl,--no-undefined")
RDMA_AddOptCFlag(CMAKE_SHARED_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-Wl,--no-undefined")

# Enable gold linker - gold has different linking checks
#RDMA_AddOptCFlag(CMAKE_EXE_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-fuse-ld=gold")
#RDMA_AddOptCFlag(CMAKE_SHARED_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-fuse-ld=gold")
#RDMA_AddOptCFlag(CMAKE_MODULE_LINKER_FLAGS SUPPORTS_NO_UNDEFINED "-fuse-ld=gold")

# Verify that GNU --version-script and asm(".symver") works
find_package(LDSymVer REQUIRED)

#-------------------------
# Find libraries
# pthread
FIND_PACKAGE (Threads REQUIRED)

# libnl
if (NOT DEFINED ENABLE_RESOLVE_NEIGH)
set(ENABLE_RESOLVE_NEIGH "ON" CACHE BOOL "Enable internal resolution of neighbours for Etherent")
endif()
if (ENABLE_RESOLVE_NEIGH)
# FIXME use of pkgconfig is discouraged
pkg_check_modules(NL3 libnl-3.0 libnl-route-3.0)
if (NL3_FOUND)
set(NL_KIND 3)
set(NL_INCLUDE_DIRS ${NL3_INCLUDE_DIRS})
set(NL_LIBRARIES ${NL3_LIBRARIES})
else()
# FIXME: I don't know why we have this fallback, all supported distros
# have libnl3
pkg_check_modules(NL1 libnl-1)
if (NL1_FOUND)
set(NL_KIND 1)
set(NL_INCLUDE_DIRS ${NL1_INCLUDE_DIRS})
set(NL_LIBRARIES ${NL1_LIBRARIES})
else()
message(FATAL_ERROR "Cannot find libnl-3.0 or libnl-1")
endif()
endif()

include_directories(${NL_INCLUDE_DIRS})
else()
set(NL_KIND 0)
set(NL_LIBRARIES "")
endif()

# Statically determine sizeof(long), this is largely unnecessary, no new code
# 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")

#-------------------------
# Apply fixups

# FIXME: We should probably always enable memcheck.h, and only selectively
# turn it off in the real high performance paths. There is no reason umad
# should ever have memcheck disabled for instance.
if (ENABLE_VALGRIND)
CHECK_INCLUDE_FILE("valgrind/memcheck.h" HAVE_VALGRIND_MEMCHECK)
CHECK_INCLUDE_FILE("valgrind/drd.h" HAVE_VALGRIND_DRD)
else()
set(HAVE_VALGRIND_MEMCHECK 0)
set(HAVE_VALGRIND_DRD 0)
endif()
RDMA_DoFixup("${HAVE_VALGRIND_MEMCHECK}" "valgrind/memcheck.h")
RDMA_DoFixup("${HAVE_VALGRIND_DRD}" "valgrind/drd.h")

# Older glibc does not include librt
CHECK_C_SOURCE_COMPILES("
#include <time.h>
int main(int argc,const char *argv[]) {
clock_gettime(CLOCK_MONOTONIC,0);
clock_nanosleep(CLOCK_MONOTONIC,0,0,0);
return 0;
};" LIBC_HAS_LIBRT)
if (NOT LIBC_HAS_LIBRT)
set(RT_LIBRARIES "rt")
endif()

#-------------------------
# Build Prep
# Write out a git ignore file to the build directory if it isn't the source
# directory. For developer convenience
if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
file(WRITE ${CMAKE_BINARY_DIR}/.gitignore "*")
endif()

configure_file("${BUILDLIB}/config.h.in" "${BUILD_INCLUDE}/config.h" ESCAPE_QUOTES @ONLY)

#-------------------------
# Sub-directories
# Libraries
add_subdirectory(libibumad/src)
add_subdirectory(libibumad/man)
add_subdirectory(libibverbs/src)
add_subdirectory(libibverbs/man)
add_subdirectory(librdmacm/src)
add_subdirectory(librdmacm/man)
add_subdirectory(libibcm/src)

# Providers
add_subdirectory(libcxgb3/src)
add_subdirectory(libcxgb4/src)
add_subdirectory(libhfi1verbs/src)
add_subdirectory(libi40iw/src)
add_subdirectory(libipathverbs/src)
add_subdirectory(libipathverbs/)
add_subdirectory(libmlx4/src)
add_subdirectory(libmlx5/src)
add_subdirectory(libmthca/src)
add_subdirectory(libnes/src)
add_subdirectory(libocrdma/src)
add_subdirectory(librxe/src)
add_subdirectory(librxe/man)
add_subdirectory(librxe/)

# Binaries
add_subdirectory(ibacm)
if (NOT NL_KIND EQUAL 0)
add_subdirectory(iwpmd/src)
endif()
add_subdirectory(libibcm/examples)
add_subdirectory(libibumad/tests)
add_subdirectory(libibverbs/examples)
add_subdirectory(librdmacm/examples)
add_subdirectory(srp_daemon/srp_daemon)
add_subdirectory(srp_daemon/man)

rdma_finalize_libs()

#-------------------------
# Display a summary
# Only report things that are non-ideal.
message(STATUS "Missing Optional Items:")
if (NOT HAVE_FUNC_ATTRIBUTE_ALWAYS_INLINE)
message(STATUS " Compiler attribute always_inline NOT supported")
endif()
if (NOT HAVE_VALGRIND_MEMCHECK)
message(STATUS " Valgrind memcheck.h NOT enabled")
endif()
if (NOT HAVE_VALGRIND_DRD)
message(STATUS " Valgrind drd.h NOT enabled")
endif()
if (NL_KIND EQUAL 1)
message(STATUS " libnl 3 NOT found (using libnl 1 compat)")
endif()
if (NL_KIND EQUAL 0)
message(STATUS " neighbour resolution NOT enabled")
endif()
if (NOT HAVE_RDMA_USER_RXE)
message(STATUS " rdma/rdma_user_rxe.h NOT found (old system kernel headers)")
endif()
if (NOT HAVE_C_WARNINGS)
message(STATUS " extended C warnings NOT supported")
endif()
if (NOT HAVE_NO_STRICT_ALIASING)
message(STATUS " -fno-strict-aliasing NOT supported")
endif()
if (NOT HAVE_C_WORKING_MISSING_FIELD_INITIALIZERS)
message(STATUS " -Wmissing-field-initializers does NOT work")
endif()
6 changes: 6 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Unless otherwise stated this software is available to you under a choice of
one of two licenses. You may choose to be licensed under the terms of the the
OpenIB.org BSD license (see COPYING.BSD) or the GNU General Public License
(GPL) Version 2 (see COPYING.GPL2), both included in this package.

Refer to individual files for information on the copyright holders.
26 changes: 26 additions & 0 deletions COPYING.BSD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
OpenIB.org BSD license

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 8d4ebd8

Please sign in to comment.