From 3a9c528c93a44a9df4df6adc140a5bf5047a7ffa Mon Sep 17 00:00:00 2001 From: Dave Larson Date: Fri, 18 Dec 2015 16:08:01 -0600 Subject: [PATCH] Squashed 'build-common/' changes from d356b1b..6591585 6591585 Create README.md 8e34b23 Add MIT License 59dab48 Merge pull request #2 from genome/gtest_compilation ac50842 fixup botched subtree/cherry-pick of last commit 927c854 add PreDepends cmake module to build common fa9ec14 Tests cannot find tr1/tuple on Max OS X Adding the compiler flag fixes this on 10.10.3 with Apple LLVM version 6.1.0 (clang-602.0.53) e2e9336 htslib installs to /usr/local by default. Update path hints. 7cb5e6a rename Findhtslib.cmake to FindHTSlib.cmake 7fa7004 add a module for finding HTSlib libraries 7e5c12e don't append PACKAGE_VERSION_SUFFIX to FULL_VERSION git-subtree-dir: build-common git-subtree-split: 6591585af458d508919e55ddcccd5cb4c50e56e9 --- LICENSE.txt | 21 +++++++++ README.md | 2 + cmake/FindHTSlib.cmake | 46 +++++++++++++++++++ cmake/PreDepends.cmake | 113 ++++++++++++++++++++++++++++++++++++++++++++++ cmake/TestHelper.cmake | 2 + cmake/VersionHelper.cmake | 2 - 6 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 cmake/FindHTSlib.cmake create mode 100644 cmake/PreDepends.cmake diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..2b6760e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2011-2015 Travis Abbott and David E. Larson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..10124c2 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# build-common +Common build scripts used in C/C++ projects. Intended to make compiling with CMake and handling dependencies slightly easier. diff --git a/cmake/FindHTSlib.cmake b/cmake/FindHTSlib.cmake new file mode 100644 index 0000000..3834cab --- /dev/null +++ b/cmake/FindHTSlib.cmake @@ -0,0 +1,46 @@ +# - Try to find htslib +# Once done, this will define +# +# htslib_FOUND - system has htslib +# htslib_INCLUDE_DIRS - the htslib include directories +# htslib_LIBRARIES - link these to use htslib + +set(HTSLIB_SEARCH_DIRS + ${HTSLIB_SEARCH_DIRS} + $ENV{HTLSIB_ROOT} + /gsc/pkg/bio/htslib + /usr + /usr/local +) + +set(_htslib_ver_path "htslib-${htslib_FIND_VERSION}") +include(LibFindMacros) + +# Dependencies +libfind_package(HTSlib ZLIB) + +# Include dir +find_path(HTSlib_INCLUDE_DIR + NAMES ${HTSLIB_ADDITIONAL_HEADERS} sam.h + PATHS ${HTSLIB_SEARCH_DIRS} + PATH_SUFFIXES + include include/htslib htslib/${_htslib_ver_path}/htslib + HINTS ENV HTSLIB_ROOT +) + +# Finally the library itself +find_library(HTSlib_LIBRARY + NAMES hts libhts.a hts.a + PATHS ${HTSlib_INCLUDE_DIR} ${HTSLIB_SEARCH_DIRS} + NO_DEFAULT_PATH + PATH_SUFFIXES lib lib64 ${_htslib_ver_path} + HINTS ENV HTSLIB_ROOT +) + +# Set the include dir variables and the libraries and let libfind_process do the rest. +# NOTE: Singular variables for this library, plural for libraries this lib depends on. +set(HTSlib_PROCESS_INCLUDES HTSlib_INCLUDE_DIR ZLIB_INCLUDE_DIR) +set(HTSlib_PROCESS_LIBS HTSlib_LIBRARY ZLIB_LIBRARIES) +libfind_process(HTSlib) +message(STATUS " HTSlib include dirs: ${HTSlib_INCLUDE_DIRS}") +message(STATUS " HTSlib libraries: ${HTSlib_LIBRARIES}") diff --git a/cmake/PreDepends.cmake b/cmake/PreDepends.cmake new file mode 100644 index 0000000..f808756 --- /dev/null +++ b/cmake/PreDepends.cmake @@ -0,0 +1,113 @@ +############################################################################## +# PreDepends.cmake +# +# Macros to cope with the fact that cmake doesn't support the notion +# of dependencies that must be built before any other target when +# doing parallel builds. +# +# SYNOPSIS: +# +# Include this file in your top level CMakeLists.txt and call +# +# PredependsInit() +# +# precisely once. +# +# Then, use + +# ExternalDependency_Add( BUILD_BYPRODUCTS ARGS ...) +# instead of +# ExternalProject_Add( BUILD_BYPRODUCTS ...) + +# xadd_executable( ...) +# instead of +# add_executable( ...) + +# xadd_library( ...) +# instead of +# add_library( ...) + + +# This will ensure that the external dependencies get built before +# any targets added with xadd_{executable,library}. + + +# METHODS: +# This module sets up a dummy target "__bc_predepends" and provides a +# macro: +# +# add_predepend(foo) +# +# This macro makes the __bc_predepends target depend on foo. It can +# be used directly, e.g., +# +# ExternalProject_Add(foo BUILD_BYPRODUCTS path/to/libfoo.a ...) +# add_predepend(foo) +# +# but the typical usage is to call +# ExternalDependency_Add(foo BUILD_BYPRODUCTS path/to/libfoo.a ARGS ...) +# instead. +# +# We provide another set of macros: +# +# xadd_executable(bar bar.c) +# xadd_library(baz baz.c) +# +# These function exactly like the native add_executable/add_library +# commands, but they also add a dependency on __bc_predepends +# to the target being generated (bar and baz in this case). +# This forces any registered predepends targets to be built first. +# In the example at hand, we get the following dependency graph: +# +# bar -----------> __bc_predepends -> foo +# libbaz.a ----` +# +# where a -> b is pronounced "a depends on b". +# +# NOTE: cmake 3.2+ is required to use the Ninja generator +cmake_minimum_required(VERSION 2.8) + +set(PREDEPENDS_TARGET_NAME "__bc_predepends") + +# Deal with multiple inclusion of this file +macro(PreDependsInit) + add_custom_target(${PREDEPENDS_TARGET_NAME} ALL) +endmacro() + +macro(add_predepend __TARGET_NAME) + add_dependencies(${PREDEPENDS_TARGET_NAME} ${__TARGET_NAME}) +endmacro() + +macro(xadd_executable __TARGET_NAME) + add_executable(${__TARGET_NAME} ${ARGN}) + add_dependencies(${__TARGET_NAME} ${PREDEPENDS_TARGET_NAME}) +endmacro() + +macro(xadd_library __TARGET_NAME) + add_library(${__TARGET_NAME} ${ARGN}) + add_dependencies(${__TARGET_NAME} ${PREDEPENDS_TARGET_NAME}) +endmacro() + +macro(ExternalDependency_Add NAME) + set(multiValueArgs BUILD_BYPRODUCTS ARGS) + cmake_parse_arguments(extdep_add "" "" "${multiValueArgs}" ${ARGN}) + + # Listing the byproducts is not needed for the "Unix Makefiles" generator. + # It is, however, required for Ninja. I don't know about any of the other + # generators... + unset(BYPRODUCTS_LIST) + if (CMAKE_GENERATOR MATCHES "Ninja") + if(CMAKE_VERSION VERSION_LESS "3.2") + message(FATAL_ERROR "The Ninja generator requires CMake 3.2+. Try the \"Unix Makefiles\" generator instead.") + endif() + set(BYPRODUCTS_LIST BUILD_BYPRODUCTS "${extdep_add_BUILD_BYPRODUCTS}") + endif() + + set(arg_list "${extdep_add_ARGS}") + ExternalProject_Add( + ${NAME} + "${BYPRODUCTS_LIST}" + "${arg_list}" + ) + add_predepend(${NAME}) +endmacro() diff --git a/cmake/TestHelper.cmake b/cmake/TestHelper.cmake index 712027d..37dbad0 100644 --- a/cmake/TestHelper.cmake +++ b/cmake/TestHelper.cmake @@ -34,6 +34,7 @@ set_property(TARGET gtest_main PROPERTY IMPORTED_LOCATION ${GTEST_MAIN_LIBRARY}) macro(add_unit_tests test_name) set(src_files ${ARGN}) add_executable(${test_name} ${src_files} ${COMMON_SOURCES}) + set_target_properties(${test_name} PROPERTIES COMPILE_FLAGS -DGTEST_USE_OWN_TR1_TUPLE=1) target_link_libraries(${test_name} ${TEST_LIBS} gtest gtest_main ${CMAKE_THREAD_LIBS_INIT}) add_dependencies(${test_name} gtest160) if($ENV{BC_UNIT_TEST_VG}) @@ -50,6 +51,7 @@ endmacro(add_unit_tests test_name src_files) macro(def_test testName) add_executable(Test${testName} Test${testName}.cpp ${COMMON_SOURCES}) + set_target_properties(${test_name} PROPERTIES COMPILE_FLAGS -DGTEST_USE_OWN_TR1_TUPLE=1) target_link_libraries(Test${testName} ${TEST_LIBS} gtest gtest_main ${CMAKE_THREAD_LIBS_INIT}) add_dependencies(Test${testName} gtest160) if($ENV{BC_UNIT_TEST_VG}) diff --git a/cmake/VersionHelper.cmake b/cmake/VersionHelper.cmake index f23ed37..b725ce9 100644 --- a/cmake/VersionHelper.cmake +++ b/cmake/VersionHelper.cmake @@ -18,5 +18,3 @@ endif() if (NOT PACKAGE_VERSION_SUFFIX) set(PACKAGE_VERSION_SUFFIX "") endif () - -set(FULL_VERSION "${FULL_VERSION}${PACKAGE_VERSION_SUFFIX}")