Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/probinso/linkwithnvcc
Browse files Browse the repository at this point in the history
  • Loading branch information
robinson96 authored Oct 23, 2017
2 parents 11993ab + 5e48a11 commit 1850589
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 15 deletions.
38 changes: 34 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,12 @@ install:
script:
# set git user info
- git config --global user.email "[email protected]"
- git config --global user.name "BLT Robot"
- git config --global user.name "BLT Robot"
- BLT_SOURCE_DIR=${TRAVIS_BUILD_DIR}
- cmake --version
- cd $TRAVIS_BUILD_DIR/..
# copy our internal testing project
- cp -r blt/cmake/blt-test .
# symlink blt into this project
- ln -s ${TRAVIS_BUILD_DIR} blt-test/blt
# create a git repo for blt-test to test the git macros
- cd blt-test
- git init
Expand All @@ -148,8 +147,10 @@ script:
- ls blt-test
# change into build dir
- cd travis-debug-build
# point to blt
- CMAKE_OPTS="-DBLT_SOURCE_DIR=${BLT_SOURCE_DIR}"
# build type and install loc
- CMAKE_OPTS="-DCMAKE_BUILD_TYPE=Debug"
- CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_BUILD_TYPE=Debug"
- CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_INSTALL_PREFIX=../travis-debug-install"
# c & c++ compilers
- CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_C_COMPILER=${BLT_CC}"
Expand Down Expand Up @@ -178,6 +179,35 @@ script:
- make
- env CTEST_OUTPUT_ON_FAILURE=1 make test
- make install
#########################################################
#########################################################
# tutorial tests
#########################################################
#########################################################
# override prev gtest setting, these projects req gtest
- CMAKE_OPTS="${CMAKE_OPTS} -DENABLE_GTEST=ON"
#########################################################
# test docs/tutorial/blank_project
#########################################################
- cd ${TRAVIS_BUILD_DIR}
- mkdir -p test-tutorial/blank_project
- cd test-tutorial/blank_project
- cmake ${CMAKE_OPTS} ${BLT_SOURCE_DIR}/docs/tutorial/blank_project
- make
- env CTEST_OUTPUT_ON_FAILURE=1 make test
- make install
#########################################################
# test docs/tutorial/calc_pi
#########################################################
- cd ${TRAVIS_BUILD_DIR}
- mkdir -p test-tutorial/calc_pi
- cd test-tutorial/calc_pi
- cmake ${CMAKE_OPTS} ${BLT_SOURCE_DIR}/docs/tutorial/calc_pi
- make
- env CTEST_OUTPUT_ON_FAILURE=1 make test
- make install



notifications:
email:
Expand Down
74 changes: 67 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ before_build:
- ps: cd ..
- mkdir build
- cp -r blt\cmake\blt-test .
- cp -r blt blt-test
# create a git repo for blt-test to test the git macros
- cd blt-test
- git init
Expand All @@ -52,9 +51,17 @@ before_build:
- git checkout -b test-branch
- git tag test-tag
- cd ..\build

build_script:
#########################################################
#########################################################
# blt-test
#########################################################
#########################################################
# configure
- echo Running cmake ...
- cmake -G "%CMAKE_GENERATOR%" ^
-D BLT_SOURCE_DIR:PATH="c:\projects\blt" ^
-D BUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% ^
-D ENABLE_GMOCK=%ENABLE_GMOCK% ^
-D ENABLE_BENCHMARKS=%ENABLE_BENCHMARKS% ^
Expand All @@ -67,16 +74,69 @@ before_build:
-D MPI_CXX_LIBRARIES:PATH="${MPI_HOME}/Lib/x86/msmpi.lib" ^
..\blt-test
- cd ..

build_script:
#build
- echo Building ...
- echo Building blt-test ...
- cmake --build build --config %CONFIG%

after_build:
# run our tests
- cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --config %CONFIG% --target RUN_TESTS

- cd ..
#########################################################
#########################################################
# tutorial tests
#########################################################
#########################################################
#########################################################
# test docs/tutorial/blank_project
#########################################################
- mkdir build-tutorial_blank_project
- cd build-tutorial_blank_project
- echo Running cmake ...
- cmake -G "%CMAKE_GENERATOR%" ^
-D BLT_SOURCE_DIR:PATH="c:\projects\blt" ^
-D BUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% ^
-D ENABLE_GMOCK=%ENABLE_GMOCK% ^
-D ENABLE_BENCHMARKS=%ENABLE_BENCHMARKS% ^
-D ENABLE_OPENMP=ON ^
-D ENABLE_MPI=%ENABLE_MPI% ^
-D MPI_HOME:PATH="C:/Program Files (x86)/Microsoft SDKs/MPI" ^
-D MPI_C_INCLUDE_PATH:PATH="${MPI_HOME}/Include" ^
-D MPI_C_LIBRARIES:PATH="${MPI_HOME}/Lib/x86/msmpi.lib" ^
-D MPI_CXX_INCLUDE_PATH:PATH="${MPI_HOME}/Include" ^
-D MPI_CXX_LIBRARIES:PATH="${MPI_HOME}/Lib/x86/msmpi.lib" ^
c:\projects\blt\docs\tutorial\blank_project
- cd ..
#build
- echo Building Tutorial Blank Project ...
- cmake --build build-tutorial_blank_project --config %CONFIG%
# run our tests
- cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build build-tutorial_blank_project --config %CONFIG% --target RUN_TESTS
- cd ..
#########################################################
# test docs/tutorial/calc_pi
#########################################################
- mkdir build-tutorial_calc_pi
- cd build-tutorial_calc_pi
- cmake -G "%CMAKE_GENERATOR%" ^
-D BLT_SOURCE_DIR:PATH="c:\projects\blt" ^
-D BUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% ^
-D ENABLE_GMOCK=%ENABLE_GMOCK% ^
-D ENABLE_BENCHMARKS=%ENABLE_BENCHMARKS% ^
-D ENABLE_OPENMP=ON ^
-D ENABLE_MPI=%ENABLE_MPI% ^
-D MPI_HOME:PATH="C:/Program Files (x86)/Microsoft SDKs/MPI" ^
-D MPI_C_INCLUDE_PATH:PATH="${MPI_HOME}/Include" ^
-D MPI_C_LIBRARIES:PATH="${MPI_HOME}/Lib/x86/msmpi.lib" ^
-D MPI_CXX_INCLUDE_PATH:PATH="${MPI_HOME}/Include" ^
-D MPI_CXX_LIBRARIES:PATH="${MPI_HOME}/Lib/x86/msmpi.lib" ^
c:\projects\blt\docs\tutorial\calc_pi
- cd ..
#build
- echo Building Tutorial Calc Pi ...
- cmake --build build-tutorial_calc_pi --config %CONFIG%
# run our tests
- cmake -E env CTEST_OUTPUT_ON_FAILURE=1 cmake --build build-tutorial_calc_pi --config %CONFIG% --target RUN_TESTS
- cd ..

on_failure:
- ps: |
Write-Output "CMakeOutput.log"
Expand Down
13 changes: 9 additions & 4 deletions cmake/blt-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ cmake_minimum_required(VERSION 3.1)

project(blt-example LANGUAGES C CXX)

################################
# Include BLT
################################
include(blt/SetupBLT.cmake)
###############################################################################
# Setup BLT
###############################################################################
# Set BLT_SOURCE_DIR to default location, if not set by user
if(NOT BLT_SOURCE_DIR)
set(BLT_SOURCE_DIR "blt")
endif()

include(${BLT_SOURCE_DIR}/SetupBLT.cmake)

################################
# Add a library
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,6 @@ The tutorial requires a C++ compiler and CMake, we recommend using CMake 3.8.0 o
unit_testing
external_dependencies
creating_documentation
recommendations


126 changes: 126 additions & 0 deletions docs/recommendations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
.. ###############################################################################
.. # Copyright (c) 2017, 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.
.. #
.. # 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 disclaimer below.
.. #
.. # * Redistributions in binary form must reproduce the above copyright notice,
.. # this list of conditions and the disclaimer (as noted below) in the
.. # documentation and/or other materials provided with the distribution.
.. #
.. # * Neither the name of the LLNS/LLNL nor the names of its contributors may
.. # be used to endorse or promote products derived from this software without
.. # specific prior written permission.
.. #
.. # 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 LAWRENCE LIVERMORE NATIONAL SECURITY,
.. # LLC, THE U.S. DEPARTMENT OF ENERGY 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.
.. #
.. ###############################################################################
.. _Recommendations:

CMake Recommendations
======================

This section includes several recommendations for how to wield CMake. Some of them are embodied in BLT, others are broader suggestions for CMake bliss.


.. rubric:: Disable in-source builds

*BLT Enforces This*


In-source builds clutter source code with temporary build files and prevent other out-of-source builds from being created. Disabling in-source builds avoids clutter and accidental checkins of temporary build files.

.. rubric:: Avoid using globs to identify source files

Globs are evaluated at CMake configure time - not build time. This means CMake will not detect new source files when they are added to the file system unless there are other changes that trigger CMake to reconfigure.

The CMake documentation also warns against this:
https://cmake.org/cmake/help/v3.10/command/file.html?highlight=glob#file


.. rubric:: Use arguments instead of options in CMake Macros and Functions

``CMAKE_PARSE_ARGUMENTS`` allows Macros or Functions to support options. Options are enabled by passing them by name when calling a Macro or Function. Because of this, wrapping an existing Macro or Function in a way that passes through options requires if tests and multiple copies of the call. For example:

.. code:: cmake
if(OPTION)
my_function(arg1 arg2 arg3 OPTION)
else()
my_function(arg1 arg2 arg3)
endif()
Adding more options compounds the logic to achieve these type of calls.

To simplify calling logic, we recommend using an argument instead of an option.

.. code:: cmake
if(OPTION)
set(arg4_value ON)
endif()
my_function(arg1 arg2 arg3 ${arg4_value})
.. rubric:: Prefer explicit paths to locate third-party dependencies

Require passing explicit paths (ex: ``ZZZ_DIR``) for third-party dependency locations. This avoids surprises with incompatible installs sprinkled in various system locations. If you are using off-the-shelf *FindZZZ* logic, also consider adding CMake checks to verify that *FindZZZ* logic actually found the dependencies at the location specified.

.. rubric:: Emit a configure error if an explicitly identified third-party dependency is not found or an incorrect version is found.

If an explicit path to a dependency is given (ex: ``ZZZ_DIR``) it should be valid or result in a CMake configure error.

In contrast, if you only issue a warning and automatically disable a feature when a third-party dependency is bad, the warning often goes unnoticed and may not be caught until folks using your software are surprised. Emitting a configure error stops CMake and draws attention to the fact that something is wrong. Optional dependencies are still supported by including them only if an explicit path to the dependency is given (ex: ``ZZZ_DIR``).



.. rubric:: Add headers as source files to targets

*BLT Macros Support This*

This ensures headers are tracked as dependencies and are included in the projects created by CMake's IDE generators, like Xcode or Eclipse.


.. rubric:: Always support `make install`

This allows CMake to do the right thing based on ``CMAKE_INSTALL_PREFIX``, and also helps support CPack create release packages. This is especially important for libraries. In addition to targets, header files require an explicit install command.

Here is an example that installs a target and its headers:

.. code:: cmake
##################################
# Install Targets for example lib
##################################
install(FILES ${example_headers} DESTINATION include)
install(TARGETS example
EXPORT example
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

0 comments on commit 1850589

Please sign in to comment.