Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cmake and directory organization. #99

Merged
merged 7 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 10 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ cmake_minimum_required(VERSION 2.8.7)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(ClangTools)

# Enable Clang auto-formatting, defaults to on.
option(ENABLE_AUTOFORMAT "Enable automatic formatting and replacement with clang-format." ON)
# Enable Clang auto-linting, defaults to off.
option(ENABLE_AUTOLINT "Enable automatic linting and warning with clang-tidy. " OFF)
# Enable static stack analyzer, defaults to off.
option(ENABLE_STACK_ANALYSIS "Enable stack analysis. Requires gcc." OFF)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -17,68 +14,22 @@ endif()

add_subdirectory(third_party/googletest)

include_directories(SYSTEM ${gtest_SOURCE_DIR} ${gtest_SOURCE_DIR}/include)
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/third_party/eigen/")
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/third_party/cereal/include")
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/third_party/fast-cpp-csv-parser/")
add_library(albatross INTERFACE)
target_include_directories(albatross INTERFACE
"${PROJECT_SOURCE_DIR}/include"
)
target_include_directories(albatross SYSTEM INTERFACE
"${PROJECT_SOURCE_DIR}/third_party/eigen/"
"${PROJECT_SOURCE_DIR}/third_party/cereal/include"
"${PROJECT_SOURCE_DIR}/third_party/fast-cpp-csv-parser/"
)


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -fexceptions -frtti")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to fix that too? take a look at what I did in orion...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just not pushed...?

set(CMAKE_CXX_FLAGS "-std=c++14 -Wshadow -Wswitch-default -Wswitch-enum -Wundef -Wpointer-arith -Wcast-align -Wformat=2 -Wredundant-decls ${CMAKE_CXX_FLAGS}")
set("LOG_LEVEL=8")

include_directories("${PROJECT_SOURCE_DIR}/albatross")
include(${PROJECT_SOURCE_DIR}/cmake/FindGFlags.cmake)

set(albatross_HEADERS
albatross/cereal/eigen.h
albatross/cereal/traits.h
albatross/core/dataset.h
albatross/core/declarations.h
albatross/core/distribution.h
albatross/core/fit_model.h
albatross/core/indexing.h
albatross/core/keys.h
albatross/core/model.h
albatross/core/parameter_handling_mixin.h
albatross/core/parameter_macros.h
albatross/core/prediction.h
albatross/core/priors.h
albatross/core/serialize.h
albatross/core/traits.h
albatross/covariance_functions/call_trace.h
albatross/covariance_functions/covariance_function.h
albatross/covariance_functions/distance_metrics.h
albatross/covariance_functions/noise.h
albatross/covariance_functions/polynomials.h
albatross/covariance_functions/radial.h
albatross/covariance_functions/scaling_function.h
albatross/covariance_functions/traits.h
albatross/csv_utils.h
albatross/eigen/serializable_diagonal_matrix.h
albatross/eigen/serializable_ldlt.h
albatross/eigen_utils.h
albatross/evaluation/cross_validation.h
albatross/evaluation/cross_validation_utils.h
albatross/evaluation/evaluate.h
albatross/evaluation/folds.h
albatross/map_utils.h
albatross/models/gp.h
albatross/models/least_squares.h
albatross/models/ransac.h
albatross/random_utils.h
albatross/tune.h
albatross/tuning_metrics.h
examples/example_utils.h
examples/sinc_example_utils.h
examples/temperature_example/temperature_example_utils.h
tests/mock_model.h
tests/test_core_distribution.h
tests/test_models.h
tests/test_serialize.h
tests/test_utils.h
)

add_custom_target(albatross DEPENDS ${albatross_HEADERS} COMMENT "albatross dependencies")

add_subdirectory(tests)
add_subdirectory(examples)
33 changes: 0 additions & 33 deletions albatross/CovarianceFunctions

This file was deleted.

72 changes: 34 additions & 38 deletions cmake/ClangTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Do not use clang tooling when cross compiling.
if(CMAKE_CROSSCOMPILING)
return()
return()
endif(CMAKE_CROSSCOMPILING)

################################################################################
Expand All @@ -21,27 +21,23 @@ endif(CMAKE_CROSSCOMPILING)
# Check for Clang format
set(CLANG_FORMAT_PATH "NOTSET" CACHE STRING "Absolute path to the clang-format executable")
if("${CLANG_FORMAT_PATH}" STREQUAL "NOTSET")
find_program(CLANG_FORMAT NAMES
clang-format39 clang-format-3.9
clang-format38 clang-format-3.8
clang-format37 clang-format-3.7
clang-format36 clang-format-3.6
clang-format35 clang-format-3.5
clang-format34 clang-format-3.4
clang-format)
message(STATUS "Using clang format: ${CLANG_FORMAT}")
if("${CLANG_FORMAT}" STREQUAL "CLANG_FORMAT-NOTFOUND")
message(WARNING "Could not find 'clang-format' please set CLANG_FORMAT_PATH:STRING")
else()
set(CLANG_FORMAT_PATH ${CLANG_FORMAT})
message(STATUS "Found: ${CLANG_FORMAT_PATH}")
endif()
find_program(CLANG_FORMAT NAMES
clang-format-6.0
clang-format-4.0
)
message(STATUS "Using clang format: ${CLANG_FORMAT}")
if("${CLANG_FORMAT}" STREQUAL "CLANG_FORMAT-NOTFOUND")
message(WARNING "Could not find 'clang-format' please set CLANG_FORMAT_PATH:STRING")
else()
set(CLANG_FORMAT_PATH ${CLANG_FORMAT})
message(STATUS "Found: ${CLANG_FORMAT_PATH}")
endif()
else()
if(NOT EXISTS ${CLANG_FORMAT_PATH})
message(WARNING "Could not find 'clang-format': ${CLANG_FORMAT_PATH}")
else()
message(STATUS "Found: ${CLANG_FORMAT_PATH}")
endif()
if(NOT EXISTS ${CLANG_FORMAT_PATH})
message(WARNING "Could not find 'clang-format': ${CLANG_FORMAT_PATH}")
else()
message(STATUS "Found: ${CLANG_FORMAT_PATH}")
endif()
endif()

################################################################################
Expand All @@ -50,24 +46,24 @@ endif()


if (EXISTS ${CLANG_FORMAT_PATH})
# Format all files .cc files (and their headers) in project
add_custom_target(clang-format-all
COMMAND git ls-files -- '../*.cc' '../*.h'
| sed 's/^...//' | sed 's\#\^\#${CMAKE_SOURCE_DIR}/\#'
| xargs "${CLANG_FORMAT_PATH}" -i
)
# In-place format *.cc files that differ from master, and are not listed as
# being DELETED.
add_custom_target(clang-format-diff
COMMAND git diff --diff-filter=ACMRTUXB --name-only master -- '../*.cc' '../*.h'
| sed 's\#\^\#${CMAKE_SOURCE_DIR}/\#'
| xargs "${CLANG_FORMAT_PATH}" -i
)
# Format all files .cc files (and their headers) in project
add_custom_target(clang-format-all
COMMAND git ls-files -- '../*.cc' '../*.h'
| sed 's/^...//' | sed 's\#^\#${CMAKE_SOURCE_DIR}/\#'
| xargs "${CLANG_FORMAT_PATH}" -i
)
# In-place format *.cc files that differ from master, and are not listed as
# being DELETED.
add_custom_target(clang-format-diff
COMMAND git diff --diff-filter=ACMRTUXB --name-only master -- '../*.cc' '../*.h'
| sed 's\#^\#${CMAKE_SOURCE_DIR}/\#'
| xargs "${CLANG_FORMAT_PATH}" -i
)
endif()
if (EXISTS ${CPPCHECK_PATH})
add_custom_target(cppcheck-all
COMMAND git ls-files -- '../*.cc' '../*.h'
| ${CPPCHECK_PATH} --enable=all --std=c++14 -I../include -isystem../third_party/eigen -q --file-list=-
)
add_custom_target(cppcheck-all
COMMAND git ls-files -- '../*.cc' '../*.h'
| ${CPPCHECK_PATH} --enable=all --std=c++14 -I../include -isystem../third_party/eigen -q --file-list=-
)
endif()

136 changes: 50 additions & 86 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,96 +1,60 @@
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/third_party/fast-cpp-csv-parser/")

set(example_HEADERS
example_utils.h
sinc_example_utils.h
CACHE INTERNAL ""
)

add_executable(sinc_example
EXCLUDE_FROM_ALL
sinc_example.cc
)

add_dependencies(sinc_example
albatross
)

target_link_libraries(sinc_example m gflags pthread nlopt)
sinc_example.cc
)
target_link_libraries(sinc_example
albatross
gflags
pthread
nlopt
)
add_custom_target(run_sinc_example
DEPENDS sinc_example
COMMAND sinc_example -input ${PROJECT_SOURCE_DIR}/examples/sinc_input.csv -output ./sinc_predictions.csv -tune
COMMENT "Running sinc_example"
)

add_custom_target(
run_sinc_example ALL
DEPENDS ${example_HEADERS}
COMMAND sinc_example -input ${PROJECT_SOURCE_DIR}/examples/sinc_input.csv -output ./sinc_predictions.csv -tune
COMMENT "Running sinc_example"
)

add_dependencies(run_sinc_example
sinc_example
)

add_executable(inspection_example
EXCLUDE_FROM_ALL
inspection.cc
)

add_dependencies(inspection_example
albatross
)

target_link_libraries(inspection_example m gflags pthread)

add_custom_target(
run_inspection_example ALL
DEPENDS ${example_HEADERS}
COMMAND inspection_example -input ${PROJECT_SOURCE_DIR}/examples/inspection_input.csv
COMMENT "Running inspection_example"
)

add_dependencies(run_inspection_example
inspection_example
)
inspection.cc
)
target_link_libraries(inspection_example
albatross
gflags
pthread
)
add_custom_target(run_inspection_example
DEPENDS inspection_example
COMMAND inspection_example -input ${PROJECT_SOURCE_DIR}/examples/inspection_input.csv
COMMENT "Running inspection_example"
)


add_executable(temperature_example
EXCLUDE_FROM_ALL
temperature_example/temperature_example.cc
)

add_dependencies(temperature_example
albatross
)

target_link_libraries(temperature_example m gflags pthread nlopt)

add_custom_target(
run_temperature_example ALL
DEPENDS ${example_HEADERS}
COMMAND temperature_example -input ${PROJECT_SOURCE_DIR}/examples/temperature_example/gsod.csv -predict ${PROJECT_SOURCE_DIR}/examples/temperature_example/prediction_locations.csv -output ./test_temperature_predictions.csv -thin 5
COMMENT "Running temperature_example"
)
temperature_example/temperature_example.cc
)
target_link_libraries(temperature_example
albatross
gflags
pthread
nlopt
)
add_custom_target(run_temperature_example
DEPENDS temperature_example
COMMAND temperature_example -input ${PROJECT_SOURCE_DIR}/examples/temperature_example/gsod.csv -predict ${PROJECT_SOURCE_DIR}/examples/temperature_example/prediction_locations.csv -output ./test_temperature_predictions.csv -thin 5
COMMENT "Running temperature_example"
)

add_dependencies(run_temperature_example
temperature_example
)

add_executable(call_trace_example
EXCLUDE_FROM_ALL
call_trace_example.cc
)

add_dependencies(call_trace_example
albatross
)

target_link_libraries(call_trace_example m gflags pthread)

add_custom_target(
run_call_trace_example ALL
DEPENDS ${example_HEADERS}
COMMAND call_trace_example
COMMENT "Running call_trace_example"
)

add_dependencies(run_call_trace_example
call_trace_example
)
call_trace_example.cc
)
target_link_libraries(call_trace_example
albatross
gflags
pthread
)
add_custom_target(run_call_trace_example
DEPENDS call_trace_example
COMMAND call_trace_example
COMMENT "Running call_trace_example"
)
7 changes: 3 additions & 4 deletions examples/call_trace_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
*/

#include "CovarianceFunctions"
#include <albatross/CovarianceFunctions>

namespace albatross {

class LinearScalar : public ScalingFunction {
public:
std::string get_name() const override { return "linear_scalar"; }

double _call_impl((const double &x) const {
return 1. + 3. * x; }
double _call_impl(const double &x) const { return 1. + 3. * x; }
};

auto complicated_covariance_function() {
Expand All @@ -30,7 +29,7 @@ auto complicated_covariance_function() {

return (constant + squared_exp) * linear_scalar;
}
}
} // namespace albatross

int main() {

Expand Down
Loading