Skip to content

Commit

Permalink
Add editorconfig support. Fix CMake indent issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcojean committed Jun 3, 2020
1 parent 617fb36 commit e43ecbf
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 207 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# More info: https://editorconfig.org

# top-most EditorConfig file
root = true

# Use space and 4 indentation style everywhere.
# Also add a newline at the end of every file.
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

# YAML files use 2 space indentation for now.
[*.{yml,md}]
indent_style = space
indent_size = 2

# Makefiles require tabs
[Makefile]
indent_style = tab
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ if(GINKGO_BUILD_TESTS AND (GINKGO_BUILD_CUDA OR GINKGO_BUILD_OMP OR GINKGO_BUILD
endif()

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()

if(BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -100,11 +100,11 @@ if(GINKGO_BUILD_TESTS)
endif()

if(GINKGO_WITH_CLANG_TIDY)
find_program(GINKGO_CLANG_TIDY_PATH clang-tidy)
find_program(GINKGO_CLANG_TIDY_PATH clang-tidy)
endif()

if(GINKGO_WITH_IWYU)
find_program(GINKGO_IWYU_PATH iwyu)
find_program(GINKGO_IWYU_PATH iwyu)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
Expand Down Expand Up @@ -227,13 +227,13 @@ if(NOT "${BASH}" STREQUAL "BASH-NOTFOUND" AND GINKGO_DEVEL_TOOLS)
endif()
unset(GIT CACHE)
add_custom_target(format_header_all
COMMAND echo "format header on all code files except build/examples/third_party/ginkgo.hpp"
COMMAND bash -c "find * -type f | \
COMMAND echo "format header on all code files except build/examples/third_party/ginkgo.hpp"
COMMAND bash -c "find * -type f | \
grep -Ev 'build|examples|third_party|ginkgo.hpp' | \
grep -E '(\.hip)?\.(cu|hpp|cuh|cpp)$' | \
xargs -r -n1 ${Ginkgo_SOURCE_DIR}/dev_tools/scripts/format_header.sh"
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR}
VERBATIM)
WORKING_DIRECTORY ${Ginkgo_SOURCE_DIR}
VERBATIM)
endif()
unset(BASH CACHE)

Expand Down Expand Up @@ -270,9 +270,9 @@ else()
endif()
add_custom_target(test_install
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -H${Ginkgo_SOURCE_DIR}/test_install
-B${Ginkgo_BINARY_DIR}/test_install
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_CONFIG_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-B${Ginkgo_BINARY_DIR}/test_install
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_CONFIG_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
# `--config cfg` is ignored by single-configuration generator.
# `$<CONFIG>` is always be the same as `CMAKE_BUILD_TYPE` in single-configuration generator.
COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_install --config $<CONFIG>
Expand Down
8 changes: 4 additions & 4 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ if (NOT CMAKE_BUILD_TYPE STREQUAL "Release")
endif()

if (GINKGO_BUILD_CUDA AND GINKGO_BUILD_HIP AND GINKGO_HIP_PLATFORM MATCHES "hcc")
message(FATAL_ERROR "Building the benchmarks for both HIP AMD and CUDA "
"at the same time is currently not supported. "
"Disable the benchmark build using `-DGINKGO_BUILD_BENCHMARKS=OFF` "
"or use `export HIP_PLATFORM=nvcc` in your build environment instead.")
message(FATAL_ERROR "Building the benchmarks for both HIP AMD and CUDA "
"at the same time is currently not supported. "
"Disable the benchmark build using `-DGINKGO_BUILD_BENCHMARKS=OFF` "
"or use `export HIP_PLATFORM=nvcc` in your build environment instead.")
endif()

function(ginkgo_benchmark_cusp_linops name)
Expand Down
70 changes: 35 additions & 35 deletions cmake/create_test.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function(ginkgo_create_test test_name)
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")
add_executable(${TEST_TARGET_NAME} ${test_name}.cpp)
target_include_directories("${TEST_TARGET_NAME}"
PRIVATE
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
)
set_target_properties(${TEST_TARGET_NAME} PROPERTIES
OUTPUT_NAME ${test_name})
Expand All @@ -17,34 +17,34 @@ function(ginkgo_create_test test_name)
endfunction(ginkgo_create_test)

function(ginkgo_create_thread_test test_name)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")
add_executable(${TEST_TARGET_NAME} ${test_name}.cpp)
target_include_directories("${TEST_TARGET_NAME}"
PRIVATE
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
)
set_target_properties(${TEST_TARGET_NAME} PROPERTIES
OUTPUT_NAME ${test_name})
if (GINKGO_CHECK_CIRCULAR_DEPS)
target_link_libraries(${TEST_TARGET_NAME} PRIVATE "${GINKGO_CIRCULAR_DEPS_FLAGS}")
endif()
target_link_libraries(${TEST_TARGET_NAME} PRIVATE ginkgo GTest::Main GTest::GTest Threads::Threads ${ARGN})
add_test(NAME ${REL_BINARY_DIR}/${test_name} COMMAND ${TEST_TARGET_NAME})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")
add_executable(${TEST_TARGET_NAME} ${test_name}.cpp)
target_include_directories("${TEST_TARGET_NAME}"
PRIVATE
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
)
set_target_properties(${TEST_TARGET_NAME} PROPERTIES
OUTPUT_NAME ${test_name})
if (GINKGO_CHECK_CIRCULAR_DEPS)
target_link_libraries(${TEST_TARGET_NAME} PRIVATE "${GINKGO_CIRCULAR_DEPS_FLAGS}")
endif()
target_link_libraries(${TEST_TARGET_NAME} PRIVATE ginkgo GTest::Main GTest::GTest Threads::Threads ${ARGN})
add_test(NAME ${REL_BINARY_DIR}/${test_name} COMMAND ${TEST_TARGET_NAME})
endfunction(ginkgo_create_thread_test)

function(ginkgo_create_test_cpp_cuda_header test_name)
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")
add_executable(${TEST_TARGET_NAME} ${test_name}.cpp)
target_include_directories("${TEST_TARGET_NAME}"
PRIVATE
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
"${CUDA_INCLUDE_DIRS}"
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
"${CUDA_INCLUDE_DIRS}"
)
set_target_properties(${TEST_TARGET_NAME} PROPERTIES
OUTPUT_NAME ${test_name})
Expand All @@ -57,12 +57,12 @@ endfunction(ginkgo_create_test_cpp_cuda_header)

function(ginkgo_create_cuda_test test_name)
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")
add_executable(${TEST_TARGET_NAME} ${test_name}.cu)
target_include_directories("${TEST_TARGET_NAME}"
PRIVATE
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
)
set_target_properties(${TEST_TARGET_NAME} PROPERTIES
OUTPUT_NAME ${test_name})
Expand All @@ -77,7 +77,7 @@ endfunction(ginkgo_create_cuda_test)
function(ginkgo_create_hip_test_special_linkage test_name)
# use gcc to compile but use hip to link
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")
add_executable(${TEST_TARGET_NAME} ${test_name}.cpp)
# Fix the missing metadata when building static library.
Expand All @@ -86,7 +86,7 @@ function(ginkgo_create_hip_test_special_linkage test_name)
endif()
target_include_directories("${TEST_TARGET_NAME}"
PRIVATE
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
)
set_target_properties(${TEST_TARGET_NAME} PROPERTIES
OUTPUT_NAME ${test_name})
Expand All @@ -99,7 +99,7 @@ endfunction(ginkgo_create_hip_test_special_linkage)

function(ginkgo_create_hip_test test_name)
file(RELATIVE_PATH REL_BINARY_DIR
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
string(REPLACE "/" "_" TEST_TARGET_NAME "${REL_BINARY_DIR}/${test_name}")

set_source_files_properties(${test_name}.hip.cpp PROPERTIES HIP_SOURCE_PROPERTY_FORMAT TRUE)
Expand All @@ -113,14 +113,14 @@ function(ginkgo_create_hip_test test_name)

target_include_directories("${TEST_TARGET_NAME}"
PRIVATE
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
# Only `math` requires it so far, but it's much easier
# to put these this way.
${GINKGO_HIP_THRUST_PATH}
# Only `exception_helpers` requires thess so far, but it's much easier
# to put these this way.
${HIPBLAS_INCLUDE_DIRS}
${HIPSPARSE_INCLUDE_DIRS}
"$<BUILD_INTERFACE:${Ginkgo_BINARY_DIR}>"
# Only `math` requires it so far, but it's much easier
# to put these this way.
${GINKGO_HIP_THRUST_PATH}
# Only `exception_helpers` requires thess so far, but it's much easier
# to put these this way.
${HIPBLAS_INCLUDE_DIRS}
${HIPSPARSE_INCLUDE_DIRS}
)
set_target_properties(${TEST_TARGET_NAME} PROPERTIES
OUTPUT_NAME ${test_name})
Expand Down
2 changes: 1 addition & 1 deletion doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ option(GINKGO_DOC_GENERATE_PDF "Generate PDF documentation" OFF)
option(GINKGO_DOC_GENERATE_DEV "Generate internal documentation" OFF)
option(GINKGO_DOC_GENERATE_EXAMPLES "Generate example documentation" ON)
if(GINKGO_DOC_GENERATE_EXAMPLES)
add_subdirectory(examples)
add_subdirectory(examples)
endif()

if (GINKGO_DOC_GENERATE_PDF)
Expand Down
126 changes: 63 additions & 63 deletions doc/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
# Collect all of the directory names for the examples programs
FILE(GLOB _ginkgo_examples
${CMAKE_SOURCE_DIR}/examples/*
)
${CMAKE_SOURCE_DIR}/examples/*
)
LIST(REMOVE_ITEM _ginkgo_examples "${CMAKE_SOURCE_DIR}/examples/CMakeLists.txt")

ADD_CUSTOM_TARGET(examples)

file(GLOB _ginkgo_examples_tooltip
${CMAKE_SOURCE_DIR}/examples/*/doc/tooltip
)
${CMAKE_SOURCE_DIR}/examples/*/doc/tooltip
)

file(GLOB _ginkgo_examples_kind
${CMAKE_SOURCE_DIR}/examples/*/doc/kind
)
${CMAKE_SOURCE_DIR}/examples/*/doc/kind
)
file(GLOB _ginkgo_examples_buildson
${CMAKE_SOURCE_DIR}/examples/*/doc/builds-on
)
${CMAKE_SOURCE_DIR}/examples/*/doc/builds-on
)

ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/examples.hpp
COMMAND ${PERL_EXECUTABLE}
ARGS
${CMAKE_SOURCE_DIR}/doc/scripts/examples.pl
${CMAKE_CURRENT_SOURCE_DIR}/examples.hpp.in
${_ginkgo_examples}
> ${CMAKE_CURRENT_BINARY_DIR}/examples.hpp
DEPENDS
${CMAKE_SOURCE_DIR}/doc/scripts/examples.pl
${CMAKE_CURRENT_SOURCE_DIR}/examples.hpp.in
${_ginkgo_examples_tooltip}
${_ginkgo_examples_kind}
${_ginkgo_examples_buildson}
)
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/examples.hpp
COMMAND ${PERL_EXECUTABLE}
ARGS
${CMAKE_SOURCE_DIR}/doc/scripts/examples.pl
${CMAKE_CURRENT_SOURCE_DIR}/examples.hpp.in
${_ginkgo_examples}
> ${CMAKE_CURRENT_BINARY_DIR}/examples.hpp
DEPENDS
${CMAKE_SOURCE_DIR}/doc/scripts/examples.pl
${CMAKE_CURRENT_SOURCE_DIR}/examples.hpp.in
${_ginkgo_examples_tooltip}
${_ginkgo_examples_kind}
${_ginkgo_examples_buildson}
)
ADD_CUSTOM_TARGET(build_examples_hpp
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/examples.hpp
COMMENT
"Building examples.hpp")
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/examples.hpp
COMMENT
"Building examples.hpp")
ADD_DEPENDENCIES(examples build_examples_hpp)

#
# Prepare the examples for documentation generation
#

FOREACH(example ${_ginkgo_examples})
GET_FILENAME_COMPONENT(example "${example}" NAME)
GET_FILENAME_COMPONENT(example "${example}" NAME)

ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${example}.cpp
COMMAND ${PERL_EXECUTABLE}
ARGS
${CMAKE_SOURCE_DIR}/doc/scripts/program2plain
< ${CMAKE_SOURCE_DIR}/examples/${example}/${example}.cpp
> ${CMAKE_CURRENT_BINARY_DIR}/${example}.cpp
DEPENDS
${CMAKE_SOURCE_DIR}/doc/scripts/program2plain
${CMAKE_SOURCE_DIR}/examples/${example}/${example}.cpp
VERBATIM
)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${example}.cpp
COMMAND ${PERL_EXECUTABLE}
ARGS
${CMAKE_SOURCE_DIR}/doc/scripts/program2plain
< ${CMAKE_SOURCE_DIR}/examples/${example}/${example}.cpp
> ${CMAKE_CURRENT_BINARY_DIR}/${example}.cpp
DEPENDS
${CMAKE_SOURCE_DIR}/doc/scripts/program2plain
${CMAKE_SOURCE_DIR}/examples/${example}/${example}.cpp
VERBATIM
)

ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${example}.hpp
COMMAND ${PERL_EXECUTABLE}
ARGS
${CMAKE_SOURCE_DIR}/doc/scripts/make_example.pl
${example} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
> ${CMAKE_CURRENT_BINARY_DIR}/${example}.hpp
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS
${CMAKE_SOURCE_DIR}/doc/scripts/make_example.pl
${CMAKE_SOURCE_DIR}/doc/scripts/intro2toc
${CMAKE_SOURCE_DIR}/doc/scripts/create_anchors
${CMAKE_SOURCE_DIR}/doc/scripts/program2doxygen
${CMAKE_SOURCE_DIR}/examples/${example}/${example}.cpp
${CMAKE_SOURCE_DIR}/examples/${example}/doc/intro.dox
${CMAKE_SOURCE_DIR}/examples/${example}/doc/results.dox
)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${example}.hpp
COMMAND ${PERL_EXECUTABLE}
ARGS
${CMAKE_SOURCE_DIR}/doc/scripts/make_example.pl
${example} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}
> ${CMAKE_CURRENT_BINARY_DIR}/${example}.hpp
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS
${CMAKE_SOURCE_DIR}/doc/scripts/make_example.pl
${CMAKE_SOURCE_DIR}/doc/scripts/intro2toc
${CMAKE_SOURCE_DIR}/doc/scripts/create_anchors
${CMAKE_SOURCE_DIR}/doc/scripts/program2doxygen
${CMAKE_SOURCE_DIR}/examples/${example}/${example}.cpp
${CMAKE_SOURCE_DIR}/examples/${example}/doc/intro.dox
${CMAKE_SOURCE_DIR}/examples/${example}/doc/results.dox
)

ADD_CUSTOM_TARGET(examples_${example}
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${example}.hpp
${CMAKE_CURRENT_BINARY_DIR}/${example}.cpp
COMMENT
ADD_CUSTOM_TARGET(examples_${example}
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${example}.hpp
${CMAKE_CURRENT_BINARY_DIR}/${example}.cpp
COMMENT
"Building doxygen input file for examples program <${example}>"
)
ADD_DEPENDENCIES(examples examples_${example})
)
ADD_DEPENDENCIES(examples examples_${example})
ENDFOREACH()
Loading

0 comments on commit e43ecbf

Please sign in to comment.