Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #29 from jpatton-USGS/updates
Browse files Browse the repository at this point in the history
Updates for Machine Learning applications - requested changes incorporated
  • Loading branch information
mguy-usgs authored Feb 5, 2019
2 parents 19112b6 + 9c4294d commit c6f47a4
Show file tree
Hide file tree
Showing 222 changed files with 10,970 additions and 5,340 deletions.
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ addons:
- libgtest-dev
- lcov
- cppcheck
- doxygen
- doxygen-doc
- doxygen-latex
- doxygen-gui
- graphviz
- unzip
sources:
- ubuntu-toolchain-r-test

Expand Down Expand Up @@ -59,14 +65,15 @@ before_script:
- g++-5 --version 2>&1 | grep g++-5

script:
# Java build, tests, and coverage
# Java build, tests, javadocs, and coverage
- cd ${TRAVIS_BUILD_DIR}/java
- ant coverage
- ant all
# C++ build, tests, and coverage
- cd ${TRAVIS_BUILD_DIR}/cpp
- mkdir build
- mkdir dist
- cd build
- cmake -DRUN_TESTS=1 -DSUPPORT_COVERAGE=1 -DRUN_COVERAGE=1 -DRUN_CPPCHECK=1 -DRAPIDJSON_PATH=../lib/rapidjson .. && make
- cmake -DRUN_TESTS=1 -DSUPPORT_COVERAGE=1 -DRUN_COVERAGE=1 -DRUN_CPPCHECK=1 -DRUN_CPPLINT=1 -DGENERATE_DOCUMENTATION=1 -DCMAKE_INSTALL_PREFIX=../dist -DRAPIDJSON_PATH=../../lib/rapidjson -DCPPLINT_PATH=../../lib/cpplint/cpplint.py -DCPPCHECK_PATH=/usr/bin/cppcheck .. && make
# python tests
- cd ${TRAVIS_BUILD_DIR}/python
- python -m unittest discover test/
Expand Down
20 changes: 20 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/lib/rapidjson/*",
"${workspaceFolder}/cpp/include/*"
],
"defines": [],
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ignore:
- "cpp/tests" # ignore tests
- "cpp/lib" # ignore external libraries
- "lib" # ignore external libraries
294 changes: 41 additions & 253 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,278 +1,66 @@
# earthquake-detection-formats CMake configuration file.
cmake_minimum_required (VERSION 3.4)
set(CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}/cmake/)

# ----- VERSION NUMBER----- #
set(VERSION_MAJOR 0)
set(VERSION_MINOR 9)
set(VERSION_PATCH 0)
# ----- PROJECT VERSION ----- #
include(${CMAKE_DIR}/version.cmake)

# ----- PROJECT ----- #
project (DetectionFormats VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
project (DetectionFormats VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})

include(internal_utils.cmake)
#----- BASE FUNCTIONS ----- #
include(${CMAKE_DIR}/base.cmake)

fix_default_compiler_settings() # Defined in internal_utils.cmake.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)

# ----- NON WINDOWS CONFIG ----- #
if (NOT MSVC)
# C++ 14 Standard
SET(GCC_CXX_14_FLAGS "-std=c++14")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_CXX_14_FLAGS} ")
# ----- CMAKE INCLUDES ----- #
include(ExternalProject)

option(SUPPORT_COVERAGE "Instrument for Coverage" OFF)
# ----- SETUP INSTALL LOCATIONS ----- #
set(INSTALL_LOCATION ${CMAKE_INSTALL_PREFIX})

if(SUPPORT_COVERAGE)
# Coverage
SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
SET(GCC_COVERAGE_LINK_FLAGS "--coverage")
# ----- PREPEND INSTALL LOCATIONS TO MODULE PATH ----- #
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${INSTALL_LOCATION}" )

# set flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_CXX_14_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
endif (SUPPORT_COVERAGE)
endif (NOT MSVC)

# ----- CMAKE CONFIG HEADER ----- #
# pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/DetectionFormatsCMakeConfig.h.in"
"${PROJECT_BINARY_DIR}/DetectionFormatsCMakeConfig.h"
)
# ----- OPTIONS ----- #
option(GENERATE_DOCUMENTATION "Create and install the HTML based API documentation" OFF)
option(RUN_TESTS "Create and run unit tests" ON)
option(RUN_CPPCHECK "Run CPP Checks (requires cppcheck installed)" OFF)
option(RUN_CPPLINT "Run CPP Checks (requires cpplint and python installed)" OFF)
option(SUPPORT_COVERAGE "Instrument for Coverage" OFF)
option(RUN_COVERAGE "Run Coverage Report (requires lcov installed)" OFF)
option(GIT_CLONE_PUBLIC "Clone from public git URLs (https)" OFF)

# ----- EXTERNAL LIBRARIES ----- #
# rapidjson
set(RAPIDJSON_PATH "${CURRENT_SOURCE_DIR}/lib/rapidjson" CACHE PATH "Path to rapidjson")

# ----- SET INCLUDE DIRECTORIES ----- #
include_directories(${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${RAPIDJSON_PATH}/..)
include_directories(${RAPIDJSON_PATH})
include(${CMAKE_DIR}/include_rapidjson.cmake)

# ----- SET SOURCE FILES ----- #
file(GLOB SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp)

# ----- SET HEADER FILES ----- #
file(GLOB HDRS ${PROJECT_SOURCE_DIR}/include/*.h)

# ----- CREATE LIBRARY ----- #
add_library (DetectionFormats STATIC ${SRCS} ${HDRS})

# ----- TARGET PROPERTIES ----- #
set_target_properties(DetectionFormats PROPERTIES
OUTPUT_NAME DetectionFormats)

# ----- GENERATE ----- #
include(GenerateExportHeader)
generate_export_header(DetectionFormats EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/DetectionFormats_export.h)

# ----- GLOBAL INCLUDES ----- #
target_include_directories(
DetectionFormats PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
)

# ----- TESTS ----- #
option(RUN_TESTS "Create and run unit tests (requires GTest)" OFF)

if (RUN_TESTS)

# ----- LOOK FOR GTEST ----- #
set(GTEST_ROOT "./" CACHE PATH "Path to the google test library")
find_package(GTest REQUIRED)

enable_testing()

# ----- TEST SOURCES ----- #
file(GLOB UNITTEST_SOURCES ${PROJECT_SOURCE_DIR}/tests/*.cpp)

if (NOT MSVC)
set(PTHREADLIB -pthread)
endif (NOT MSVC)

# ----- SET TEST INCLUDE DIRECTORIES ----- #
include_directories(${GTEST_INCLUDE_DIRS})

# ----- CREATE TEST EXE ----- #
add_executable(DetectionFormatsTests ${UNITTEST_SOURCES})
set_target_properties(DetectionFormatsTests PROPERTIES OUTPUT_NAME DetectionFormats-tests)
target_link_libraries(DetectionFormatsTests ${PTHREADLIB} ${GCC_COVERAGE_LINK_FLAGS} ${GTEST_BOTH_LIBRARIES})
target_link_libraries(DetectionFormatsTests DetectionFormats)

# ----- TESTS ----- #
GTEST_ADD_TESTS(DetectionFormatsTests "" ${UNITTEST_SOURCES})

# ----- RUN TESTS ----- #
add_custom_command(TARGET DetectionFormatsTests
POST_BUILD
COMMAND DetectionFormatsTests
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running DetectionFormatsTests" VERBATIM
)

# ----- RUN COVERAGE ----- #
if(SUPPORT_COVERAGE)

option(RUN_COVERAGE "Run Coverage Report (requires lcov installed)" OFF)

if(RUN_COVERAGE)
add_custom_target(coverage-report ALL
DEPENDS DetectionFormatsTests
COMMAND /bin/sh
${PROJECT_SOURCE_DIR}/generate_coverage.sh
COMMENT "Capture/Report Coverage Info" VERBATIM
)

endif (RUN_COVERAGE)

endif (SUPPORT_COVERAGE)
endif()

# ----- CPPCHECK ----- #
option(RUN_CPPCHECK "Run CPP Checks (requires cppcheck installed)" OFF)

if(RUN_CPPCHECK)

file(GLOB CPPCHECK_SRCS "${PROJECT_SOURCE_DIR}/include/*.h" "${PROJECT_SOURCE_DIR}/src/*.cpp")

add_custom_target(cppcheck ALL
DEPENDS DetectionFormats
COMMAND cppcheck
--enable=warning,performance,portability
--language=c++
--std=c++11
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
--verbose
--suppress=nullPointerRedundantCheck
--error-exitcode=1
${CPPCHECK_SRCS}
COMMENT "Running cppcheck" VERBATIM
)
endif()

# ----- CPPLINT ----- #
option(RUN_CPPLINT "Run CPP Checks (requires cpplint and python installed)" OFF)

if(RUN_CPPLINT)

set(CPPLINT_PATH "${CURRENT_SOURCE_DIR}/lib/cpplint/cpplint.py" CACHE FILEPATH "Path to cpplint")
file(GLOB CPPLINT_SRCS "${PROJECT_SOURCE_DIR}/include/*.h"
"${PROJECT_SOURCE_DIR}/src/*.cpp")

add_custom_target(cpplint ALL
DEPENDS DetectionFormats
COMMAND /usr/bin/python "${CPPLINT_PATH}"
--filter=-whitespace/tab,-legal/copyright,-build/c++11,-build/header_guard,-readability/fn_size,-runtime/references
${CPPLINT_SRCS}
COMMENT "Running cpplint" VERBATIM
)
endif()

# ----- DOCUMENTATION ----- #
option(GENERATE_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" OFF)

if(GENERATE_DOCUMENTATION)

# ----- LOOK FOR DOXYGEN ----- #
find_package(Doxygen REQUIRED)

set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

configure_file(${doxyfile_in} ${doxyfile} @ONLY)

add_custom_target(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)

install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION doc/${PROJECT_NAME}
)
endif()

# ----- INSTALL RULES ----- #
# Layout. This works for all platforms:
# * <prefix>/lib/<PROJECT-NAME>
# * <prefix>/lib/
# * <prefix>/include/
set(config_install_dir "lib/${PROJECT_NAME}")
set(include_install_dir "include")

set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")

# ----- Configuration ----- #
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")

# Include module with function 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)

# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Note: PROJECT_VERSION is used as a VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)

# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * targets_export_name
# * PROJECT_NAME
configure_package_config_file(
"Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)

# Targets:
# * <prefix>/lib/libDetectionFormats.a
# * header location after install: <prefix>/include/*.h
install(
TARGETS DetectionFormats
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
# ----- BUILD LIBRARY ----- #
include(${CMAKE_DIR}/build_lib.cmake)

# Headers:
# * *.h-> <prefix>/include/*.h
install(
FILES ${HDRS}
DESTINATION "${include_install_dir}/${PROJECT_NAME}"
)
# ----- RUN CPPCHECK ----- #
include(${CMAKE_DIR}/cppcheck.cmake)

install(
DIRECTORY ${RAPIDJSON_PATH}
DESTINATION "${include_install_dir}"
)
# ----- RUN CPPLINT ----- #
include(${CMAKE_DIR}/cpplint.cmake)

# Export headers:
# * ${CMAKE_CURRENT_BINARY_DIR}/DetectionFormats_export.h -> <prefix>/include/DetectionFormats_export.h
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/DetectionFormats_export.h"
DESTINATION "${include_install_dir}"
)
# ----- RUN UNIT TESTS ----- #
file(GLOB TESTS ${PROJECT_SOURCE_DIR}/tests/*.cpp)
# WARNING: linking order of libraries matters for G++
set(TEST_LIBRARIES ${SuperEasyJSON_LIBRARIES} ${util_LIBRARIES} ${DetectionFormats_LIBRARIES})
include(${CMAKE_DIR}/test.cmake)

# Config
# * <prefix>/lib/DetectionFormats/DetectionFormatsConfig.cmake
# * <prefix>/lib/DetectionFormats/DetectionFormatsConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
# ----- GENERATE DOCUMENTATION ----- #
set(DOC_DIRS "${PROJECT_SOURCE_DIR}/include/")
include(${CMAKE_DIR}/documentation.cmake)

# Config
# * <prefix>/lib/DetectionFormats/DetectionFormatsTargets.cmake
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
# ----- INSTALL LIBRARY ----- #
include(${CMAKE_DIR}/install_lib.cmake)
4 changes: 0 additions & 4 deletions cpp/DetectionFormatsCMakeConfig.h.in

This file was deleted.

13 changes: 0 additions & 13 deletions cpp/Doxyfile.in

This file was deleted.

Loading

0 comments on commit c6f47a4

Please sign in to comment.