From ea3eabdec5205c8ba2f21bac14396b692913ec0f Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 15 Feb 2019 16:08:08 -0800 Subject: [PATCH] Support Object libraries, add tests, add release notes, bump version number and report it --- LICENSE | 2 +- README.md | 4 +- RELEASE-NOTES.md | 35 ++++++ SetupBLT.cmake | 7 +- cmake/BLTMacros.cmake | 104 ++++++++++++------ cmake/BLTPrivateMacros.cmake | 40 ++++--- tests/internal/CMakeLists.txt | 4 +- .../src/object_library_test/CMakeLists.txt | 34 ++++++ .../src/object_library_test/base_object.cpp | 19 ++++ .../src/object_library_test/base_object.hpp | 19 ++++ .../internal/src/object_library_test/main.cpp | 34 ++++++ .../src/object_library_test/object.cpp | 20 ++++ .../src/object_library_test/object.hpp | 19 ++++ 13 files changed, 289 insertions(+), 52 deletions(-) create mode 100644 RELEASE-NOTES.md create mode 100644 tests/internal/src/object_library_test/CMakeLists.txt create mode 100644 tests/internal/src/object_library_test/base_object.cpp create mode 100644 tests/internal/src/object_library_test/base_object.hpp create mode 100644 tests/internal/src/object_library_test/main.cpp create mode 100644 tests/internal/src/object_library_test/object.cpp create mode 100644 tests/internal/src/object_library_test/object.hpp diff --git a/LICENSE b/LICENSE index 323d403b2..9c5ca2178 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2017, Lawrence Livermore National Security, LLC. +Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory diff --git a/README.md b/README.md index 6cfb1f2a3..9ec047080 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -BLT v0.1 +BLT v0.2 ======== [![Build Status](https://travis-ci.org/LLNL/blt.svg)](https://travis-ci.org/LLNL/blt) @@ -29,7 +29,7 @@ Developers include: Release ------- -Copyright (c) 2017, Lawrence Livermore National Security, LLC. +Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory. diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md new file mode 100644 index 000000000..e663fc719 --- /dev/null +++ b/RELEASE-NOTES.md @@ -0,0 +1,35 @@ +# BLT Software Release Notes + +Notes describing significant changes in each BLT release are documented +in this file. + +The format of this file is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). + +The Axom project release numbers follow [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## 0.2.0 - Release date 2019-02-15 + +### Added +- Release notes... +- Object library support through blt_add_library(... OBJECT TRUE ...) +- Now reporting BLT version through CMake cache variable BLT_VERSION +- Output CMake version and executable used during CMake step +- Clang-query support now added (Thanks David Poliakoff) + +### Removed + +### Deprecated + +### Changed + +### Fixed +- Incorrect use of cuda vs cuda_runtime targets +- Improved tutorial documentation +- Incorrect use of Fortran flags with CUDA (Thanks Robert Blake) +- Handle correctly CMake version differences with CUDA host compiler variables + (Thanks Randy Settgast) +- Handle uncrustify (version 0.68) command line option changes (--no-backup) + +### Known Bugs + + diff --git a/SetupBLT.cmake b/SetupBLT.cmake index 07fb31ec8..4dea0f7cb 100644 --- a/SetupBLT.cmake +++ b/SetupBLT.cmake @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2017, Lawrence Livermore National Security, LLC. +# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. # # Produced at the Lawrence Livermore National Laboratory # @@ -41,7 +41,10 @@ ############################################################################### if (NOT BLT_LOADED) - set (BLT_LOADED True) + set(BLT_VERSION "0.2.0") + message(STATUS "BLT Version: ${BLT_VERSION}") + + set(BLT_LOADED True) mark_as_advanced(BLT_LOADED) set( BLT_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "" FORCE ) diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index 880be96fb..bf2628802 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -291,6 +291,7 @@ endmacro(blt_add_target_link_flags) ## ## Output variables (name = "foo"): ## BLT_FOO_IS_REGISTERED_LIBRARY +## BLT_FOO_IS_OBJECT_LIBRARY ## BLT_FOO_DEPENDS_ON ## BLT_FOO_INCLUDES ## BLT_FOO_TREAT_INCLUDES_AS_SYSTEM @@ -302,7 +303,7 @@ endmacro(blt_add_target_link_flags) ##------------------------------------------------------------------------------ macro(blt_register_library) - set(singleValueArgs NAME TREAT_INCLUDES_AS_SYSTEM) + set(singleValueArgs NAME OBJECT TREAT_INCLUDES_AS_SYSTEM) set(multiValueArgs INCLUDES DEPENDS_ON FORTRAN_MODULES @@ -329,6 +330,13 @@ macro(blt_register_library) mark_as_advanced(BLT_${uppercase_name}_INCLUDES) endif() + if( ${arg_OBJECT} ) + set(BLT_${uppercase_name}_IS_OBJECT_LIBRARY ON CACHE BOOL "" FORCE) + else() + set(BLT_${uppercase_name}_IS_OBJECT_LIBRARY OFF CACHE BOOL "" FORCE) + endif() + mark_as_advanced(BLT_${uppercase_name}_IS_OBJECT_LIBRARY) + if( ${arg_TREAT_INCLUDES_AS_SYSTEM} ) set(BLT_${uppercase_name}_TREAT_INCLUDES_AS_SYSTEM ON CACHE BOOL "" FORCE) else() @@ -370,17 +378,18 @@ endmacro(blt_register_library) ##------------------------------------------------------------------------------ -## blt_add_library( NAME -## SOURCES [source1 [source2 ...]] -## HEADERS [header1 [header2 ...]] -## INCLUDES [dir1 [dir2 ...]] -## DEFINES [define1 [define2 ...]] -## DEPENDS_ON [dep1 ...] -## OUTPUT_NAME [name] -## OUTPUT_DIR [dir] -## SHARED [TRUE | FALSE] +## blt_add_library( NAME +## SOURCES [source1 [source2 ...]] +## HEADERS [header1 [header2 ...]] +## INCLUDES [dir1 [dir2 ...]] +## DEFINES [define1 [define2 ...]] +## DEPENDS_ON [dep1 ...] +## OUTPUT_NAME [name] +## OUTPUT_DIR [dir] +## SHARED [TRUE | FALSE] +## OBJECT [TRUE | FALSE] ## CLEAR_PREFIX [TRUE | FALSE] -## FOLDER [name] +## FOLDER [name] ## ) ## ## Adds a library target, called , to be built from the given sources. @@ -388,6 +397,14 @@ endmacro(blt_register_library) ## whether the library will be build as shared or static. The optional boolean ## SHARED argument can be used to override this choice. ## +## The OBJECT argument creates a CMake object library. Basically it is a collection +## of compiled source files that are not archived or linked. Unlike regular CMake +## object libraries you do not have to use the $> syntax, +## you can just use . +## Note: Object libraries do not follow CMake's transitivity rules until 3.13. +## BLT will add the various information provided in this macro in the order +## you provide them to help. +## ## The INCLUDES argument allows you to define what include directories are ## needed by any target that is dependent on this library. These will ## be inherited by CMake's target dependency rules. @@ -417,19 +434,28 @@ endmacro(blt_register_library) ## FOLDER is an optional keyword to organize the target into a folder in an IDE. ## This is available when ENABLE_FOLDERS is ON and when the cmake generator ## supports this feature and will otherwise be ignored. -## Note: Do not use with header-only (INTERFACE)libraries, as this will generate -## a cmake configuration error. +## Note: Do not use with header-only (INTERFACE)libraries, as this will generate +## a cmake configuration error. ##------------------------------------------------------------------------------ macro(blt_add_library) set(options) - set(singleValueArgs NAME OUTPUT_NAME OUTPUT_DIR HEADERS_OUTPUT_SUBDIR SHARED CLEAR_PREFIX FOLDER) + set(singleValueArgs NAME OUTPUT_NAME OUTPUT_DIR HEADERS_OUTPUT_SUBDIR SHARED OBJECT CLEAR_PREFIX FOLDER) set(multiValueArgs SOURCES HEADERS INCLUDES DEFINES DEPENDS_ON) # parse the arguments cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} ) + # Default values + if(NOT DEFINED arg_OBJECT) + set(arg_OBJECT FALSE) + endif() + + if(NOT DEFINED arg_SHARED) + set(arg_SHARED FALSE) + endif() + # sanity checks if( "${arg_NAME}" STREQUAL "" ) message(FATAL_ERROR "blt_add_library() must be called with argument NAME ") @@ -439,31 +465,45 @@ macro(blt_add_library) message(FATAL_ERROR "blt_add_library(NAME ${arg_NAME} ...) called with no given sources or headers") endif() - # Determine whether to build as a shared library. Default to global variable unless - # SHARED parameter is specified - set(_build_shared_library ${BUILD_SHARED_LIBS}) - if( DEFINED arg_SHARED ) - set(_build_shared_library ${arg_SHARED}) + if (arg_OBJECT) + if (arg_SHARED) + message(FATAL_ERROR "blt_add_library(NAME ${arg_NAME} ...) cannot be called with both OBJECT and SHARED set to TRUE.") + endif() + + if (NOT arg_SOURCES) + message(FATAL_ERROR "blt_add_library(NAME ${arg_NAME} ...) cannot create an object library with no sources.") + endif() endif() if ( arg_SOURCES ) + # Determine type of library to build. STATIC by default and OBJECT takes + # precedence over global BUILD_SHARED_LIBS variable. + set(_build_shared_library ${BUILD_SHARED_LIBS}) + if( DEFINED arg_SHARED ) + set(_build_shared_library ${arg_SHARED}) + endif() + if ( ${_build_shared_library} ) - add_library( ${arg_NAME} SHARED ${arg_SOURCES} ${arg_HEADERS} ) + set(_lib_type "SHARED") + elseif ( ${arg_OBJECT} ) + set(_lib_type "OBJECT") + blt_register_library( NAME ${arg_NAME} + DEPENDS_ON ${arg_DEPENDS_ON} + INCLUDES ${arg_INCLUDES} + OBJECT TRUE + DEFINES ${arg_DEFINES} ) else() - add_library( ${arg_NAME} STATIC ${arg_SOURCES} ${arg_HEADERS} ) + set(_lib_type "STATIC") endif() + add_library( ${arg_NAME} ${_lib_type} ${arg_SOURCES} ${arg_HEADERS} ) + if (ENABLE_CUDA AND NOT ENABLE_CLANG_CUDA) - if ( ${_build_shared_library} ) - set(_target_type "shared") - else() - set(_target_type "static") - endif() blt_setup_cuda_target( NAME ${arg_NAME} SOURCES ${arg_SOURCES} DEPENDS_ON ${arg_DEPENDS_ON} - LIBRARY_TYPE ${_target_type}) + LIBRARY_TYPE ${_lib_type}) endif() else() # @@ -504,8 +544,9 @@ macro(blt_add_library) target_include_directories(${arg_NAME} PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY}) endif() - blt_setup_target( NAME ${arg_NAME} - DEPENDS_ON ${arg_DEPENDS_ON} ) + blt_setup_target( NAME ${arg_NAME} + DEPENDS_ON ${arg_DEPENDS_ON} + OBJECT ${arg_OBJECT}) if ( arg_INCLUDES ) target_include_directories(${arg_NAME} PUBLIC ${arg_INCLUDES}) @@ -609,8 +650,9 @@ macro(blt_add_executable) target_include_directories(${arg_NAME} PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY}) endif() - blt_setup_target(NAME ${arg_NAME} - DEPENDS_ON ${arg_DEPENDS_ON} ) + blt_setup_target(NAME ${arg_NAME} + DEPENDS_ON ${arg_DEPENDS_ON} + OBJECT FALSE) if ( arg_INCLUDES ) target_include_directories(${arg_NAME} PUBLIC ${arg_INCLUDES}) diff --git a/cmake/BLTPrivateMacros.cmake b/cmake/BLTPrivateMacros.cmake index 14f7105f0..ebda09edf 100644 --- a/cmake/BLTPrivateMacros.cmake +++ b/cmake/BLTPrivateMacros.cmake @@ -115,12 +115,14 @@ endmacro(blt_find_executable) ##------------------------------------------------------------------------------ -## blt_setup_target( NAME [name] DEPENDS_ON [dep1 ...] ) +## blt_setup_target( NAME [name] +## DEPENDS_ON [dep1 ...] +## OBJECT [TRUE | FALSE]) ##------------------------------------------------------------------------------ macro(blt_setup_target) set(options) - set(singleValueArgs NAME) + set(singleValueArgs NAME OBJECT) set(multiValueArgs DEPENDS_ON) # Parse the arguments @@ -152,6 +154,12 @@ macro(blt_setup_target) foreach( dependency ${_expanded_DEPENDS_ON} ) string(TOUPPER ${dependency} uppercase_dependency ) + if ( NOT ${arg_OBJECT} ) + if ( BLT_${uppercase_dependency}_IS_OBJECT_LIBRARY ) + target_sources(${arg_NAME} PRIVATE $) + endif() + endif() + if ( DEFINED BLT_${uppercase_dependency}_INCLUDES ) if ( BLT_${uppercase_dependency}_TREAT_INCLUDES_AS_SYSTEM ) target_include_directories( ${arg_NAME} SYSTEM PUBLIC @@ -167,17 +175,19 @@ macro(blt_setup_target) ${BLT_${uppercase_dependency}_FORTRAN_MODULES} ) endif() - if ( DEFINED BLT_${uppercase_dependency}_LIBRARIES) - # This prevents cmake from adding -l to the - # command line for BLT registered libraries which are not - # actual CMake targets - if(NOT "${BLT_${uppercase_dependency}_LIBRARIES}" - STREQUAL "BLT_NO_LIBRARIES" ) - target_link_libraries( ${arg_NAME} PUBLIC - ${BLT_${uppercase_dependency}_LIBRARIES} ) + if ( NOT ${arg_OBJECT} ) + if (DEFINED BLT_${uppercase_dependency}_LIBRARIES) + # This prevents cmake from adding -l to the + # command line for BLT registered libraries which are not + # actual CMake targets + if(NOT "${BLT_${uppercase_dependency}_LIBRARIES}" + STREQUAL "BLT_NO_LIBRARIES" ) + target_link_libraries( ${arg_NAME} PUBLIC + ${BLT_${uppercase_dependency}_LIBRARIES} ) + endif() + else() + target_link_libraries( ${arg_NAME} PUBLIC ${dependency} ) endif() - else() - target_link_libraries( ${arg_NAME} PUBLIC ${dependency} ) endif() if ( DEFINED BLT_${uppercase_dependency}_DEFINES ) @@ -190,7 +200,7 @@ macro(blt_setup_target) FLAGS ${BLT_${uppercase_dependency}_COMPILE_FLAGS} ) endif() - if ( DEFINED BLT_${uppercase_dependency}_LINK_FLAGS ) + if ( NOT ${arg_OBJECT} AND DEFINED BLT_${uppercase_dependency}_LINK_FLAGS ) blt_add_target_link_flags(TO ${arg_NAME} FLAGS ${BLT_${uppercase_dependency}_LINK_FLAGS} ) endif() @@ -203,7 +213,7 @@ endmacro(blt_setup_target) ## blt_setup_cuda_target(NAME ## SOURCES ## DEPENDS_ON -## LIBRARY_TYPE ) +## LIBRARY_TYPE ) ##------------------------------------------------------------------------------ macro(blt_setup_cuda_target) @@ -266,7 +276,7 @@ macro(blt_setup_cuda_target) if (${arg_LIBRARY_TYPE} STREQUAL "static") set_target_properties( ${arg_NAME} PROPERTIES CMAKE_CUDA_CREATE_STATIC_LIBRARY ON) - else(${arg_LIBRARY_TYPE} STREQUAL "shared") + else() set_target_properties( ${arg_NAME} PROPERTIES CMAKE_CUDA_CREATE_STATIC_LIBRARY OFF) endif() diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index ea84e4644..a47031cc1 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -44,7 +44,6 @@ # BLT Internal Testing Project ################################ -################################ cmake_minimum_required(VERSION 3.1) project(blt-example LANGUAGES C CXX) @@ -231,6 +230,9 @@ message(STATUS "") foreach(_target gtest example t_example_smoke not-a-target blt_header_only mpi) blt_print_target_properties(TARGET ${_target}) endforeach() + +add_subdirectory(src/object_library_test) + if(ENABLE_CLANGQUERY) add_subdirectory(src/static_analysis) endif() diff --git a/tests/internal/src/object_library_test/CMakeLists.txt b/tests/internal/src/object_library_test/CMakeLists.txt new file mode 100644 index 000000000..a4aefbfdd --- /dev/null +++ b/tests/internal/src/object_library_test/CMakeLists.txt @@ -0,0 +1,34 @@ +############################################################################### +# Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. +# +# Produced at the Lawrence Livermore National Laboratory +# +# LLNL-CODE-725085 +# +# All rights reserved. +# +# This file is part of BLT. +# +# For additional details, please also read BLT/LICENSE. +############################################################################### +# +# Simple test that uses the blt_add_library macro with object libraries +# +############################################################################### + +blt_add_library( NAME base_object + SOURCES base_object.cpp + HEADERS base_object.hpp + OBJECT TRUE) + +blt_add_library( NAME object + SOURCES object.cpp + HEADERS object.hpp + DEPENDS_ON base_object + OBJECT TRUE) + +blt_add_executable( NAME blt_test_object_libraries + SOURCES main.cpp + DEPENDS_ON object) +blt_add_test( NAME blt_test_object_libraries + COMMAND blt_test_object_libraries) diff --git a/tests/internal/src/object_library_test/base_object.cpp b/tests/internal/src/object_library_test/base_object.cpp new file mode 100644 index 000000000..b69bd2b23 --- /dev/null +++ b/tests/internal/src/object_library_test/base_object.cpp @@ -0,0 +1,19 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. +// +// Produced at the Lawrence Livermore National Laboratory +// +// LLNL-CODE-725085 +// +// All rights reserved. +// +// This file is part of BLT. +// +// For additional details, please also read BLT/LICENSE. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#include "base_object.hpp" + +int base_number() +{ + return 2; +} \ No newline at end of file diff --git a/tests/internal/src/object_library_test/base_object.hpp b/tests/internal/src/object_library_test/base_object.hpp new file mode 100644 index 000000000..20f54e63d --- /dev/null +++ b/tests/internal/src/object_library_test/base_object.hpp @@ -0,0 +1,19 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. +// +// Produced at the Lawrence Livermore National Laboratory +// +// LLNL-CODE-725085 +// +// All rights reserved. +// +// This file is part of BLT. +// +// For additional details, please also read BLT/LICENSE. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#ifndef BASE_OBJECT_HPP +#define BASE_OBJECT_HPP + +int base_number(); + +#endif \ No newline at end of file diff --git a/tests/internal/src/object_library_test/main.cpp b/tests/internal/src/object_library_test/main.cpp new file mode 100644 index 000000000..adc6a82d7 --- /dev/null +++ b/tests/internal/src/object_library_test/main.cpp @@ -0,0 +1,34 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. +// +// Produced at the Lawrence Livermore National Laboratory +// +// LLNL-CODE-725085 +// +// All rights reserved. +// +// This file is part of BLT. +// +// For additional details, please also read BLT/LICENSE. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#include "object.hpp" + +#include + +int main() +{ + int number = object_number(); + if(number == 3) { + std::cout << number + << " was correctly returned from object and base library." + << std::endl; + return 0; + } + std::cerr << "Error:" + << number + << " was returned from object and base library." + << std::endl + << "3 was the correct number." + << std::endl; + return 1; +} diff --git a/tests/internal/src/object_library_test/object.cpp b/tests/internal/src/object_library_test/object.cpp new file mode 100644 index 000000000..977270885 --- /dev/null +++ b/tests/internal/src/object_library_test/object.cpp @@ -0,0 +1,20 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. +// +// Produced at the Lawrence Livermore National Laboratory +// +// LLNL-CODE-725085 +// +// All rights reserved. +// +// This file is part of BLT. +// +// For additional details, please also read BLT/LICENSE. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#include "base_object.hpp" +#include "object.hpp" + +int object_number() +{ + return 1 + base_number(); +} \ No newline at end of file diff --git a/tests/internal/src/object_library_test/object.hpp b/tests/internal/src/object_library_test/object.hpp new file mode 100644 index 000000000..84ef6f1b1 --- /dev/null +++ b/tests/internal/src/object_library_test/object.hpp @@ -0,0 +1,19 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC. +// +// Produced at the Lawrence Livermore National Laboratory +// +// LLNL-CODE-725085 +// +// All rights reserved. +// +// This file is part of BLT. +// +// For additional details, please also read BLT/LICENSE. +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +#ifndef OBJECT_HPP +#define OBJECT_HPP + +int object_number(); + +#endif \ No newline at end of file