Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
76 changes: 76 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- Python -*-

with section("format"):

# How wide to allow formatted cmake files
line_width = 100

# How many spaces to tab for indent
tab_size = 2

# If true, separate flow control names from their parentheses with a space
separate_ctrl_name_with_space = False

# If true, separate function names from parentheses with a space
separate_fn_name_with_space = False

# If a statement is wrapped to more than one line, then dangle the closing
# parenthesis on its own line.
dangle_parens = False

# If a positional argument group contains more than this many arguments, then
# force it to a vertical layout.
max_pargs_hwrap = 3

# Force vertical alignment if command takes more than this number of lines
max_rows_cmdline = 1

# List of command names which should always be wrapped
always_wrap = ['configure_package_config_file',
'list',
'set_target_properties',
'target_include_directories',
'target_link_libraries',
'FILES',
'HEADERS',
'INCLUDE_DIRECTORIES',
'LINK_LIBRARIES',
'NAMES',
'PATHS',
'PATH_SUFFIXES',
'SOURCES'
]

with section("parse"):

# Formatting for custom macros
additional_commands = {
"gridkit_add_library": {
"pargs": 1, # Number of initial positional arguments
"flags": [],
"kwargs": {
"SOURCES": "*",
"HEADERS": "*",
"LINK_LIBRARIES": "*",
"INCLUDE_DIRECTORIES": "*",
"COMPILE_OPTIONS": "*",
}
},
"enzyme_build_object": {
"flags": [],
"kwargs": {
"NAME": 1,
"SOURCES": "*",
"LINK_LIBRARIES": "*",
"INCLUDE_DIRECTORIES": "*",
}
}
}

with section("markup"):

# Globally disable comment markup processing
enable_markup = False

# Do not reflow the first comment block in each file
first_comment_is_literal = True
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
repos:
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- Added node objects to `PowerElectronics` module & updated all examples to make use of them.
- Separated internal and external residuals of `PowerElectronics` models.
- Added `CliArgs` class for better management of command-line options.
- Added cmake-format hooks, including in pre-commit.

## v0.1

Expand Down
81 changes: 53 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

cmake_minimum_required(VERSION 3.13)

project(GridKit
VERSION 0.1.0
LANGUAGES CXX)
project(
GridKit
VERSION 0.1.0
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (MSVC)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -Wpedantic")
Expand All @@ -39,7 +40,14 @@ option(GridKit_ENABLE_ASAN "Enable the address sanitizer" OFF)
option(GridKit_ENABLE_UBSAN "Enable the undefined behavior sanitizer" OFF)

# This allows use of "GRIDKIT_*" versions of the above options
list(APPEND _gridkit_enable_options IPOPT SUNDIALS ENZYME ASAN UBSAN)
list(
APPEND
_gridkit_enable_options
IPOPT
SUNDIALS
ENZYME
ASAN
UBSAN)
foreach(_opt IN LISTS _gridkit_enable_options)
if(NOT DEFINED GRIDKIT_ENABLE_${_opt})
set(GRIDKIT_ENABLE_${_opt} ${GridKit_ENABLE_${_opt}})
Expand All @@ -48,19 +56,28 @@ endforeach()

# Sanitizers
if(GRIDKIT_ENABLE_ASAN)
set(GRIDKIT_COMPILE_OPTIONS ${GRIDKIT_COMPILE_OPTIONS} -fsanitize=address -fno-omit-frame-pointer CACHE INTERNAL STRING)
set(GRIDKIT_LINK_OPTIONS ${GRIDKIT_LINK_OPTIONS} -fsanitize=address CACHE INTERNAL STRING)
set(GRIDKIT_COMPILE_OPTIONS
${GRIDKIT_COMPILE_OPTIONS} -fsanitize=address -fno-omit-frame-pointer
CACHE INTERNAL STRING)
set(GRIDKIT_LINK_OPTIONS
${GRIDKIT_LINK_OPTIONS} -fsanitize=address
CACHE INTERNAL STRING)
endif()

if(GRIDKIT_ENABLE_UBSAN)
set(GRIDKIT_COMPILE_OPTIONS ${GRIDKIT_COMPILE_OPTIONS} -fsanitize=undefined -fno-omit-frame-pointer CACHE INTERNAL STRING)
set(GRIDKIT_LINK_OPTIONS ${GRIDKIT_LINK_OPTIONS} -fsanitize=undefined CACHE INTERNAL STRING)
set(GRIDKIT_COMPILE_OPTIONS
${GRIDKIT_COMPILE_OPTIONS} -fsanitize=undefined -fno-omit-frame-pointer
CACHE INTERNAL STRING)
set(GRIDKIT_LINK_OPTIONS
${GRIDKIT_LINK_OPTIONS} -fsanitize=undefined
CACHE INTERNAL STRING)
endif()

set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
list(
APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath
# use, i.e. don't skip the full RPATH for the build tree
Expand All @@ -77,9 +94,13 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
list(
FIND
CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${CMAKE_INSTALL_PREFIX}/lib"
isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Expand All @@ -90,12 +111,19 @@ if(GRIDKIT_ENABLE_IPOPT)
endif()
if(GRIDKIT_ENABLE_SUNDIALS)
enable_language(C)
find_package(SUNDIALS 7.4.0 REQUIRED CONFIG
PATHS ${SUNDIALS_DIR}
${SUNDIALS_DIR}/lib/cmake/sundials)
find_package(
SUNDIALS
7.4.0
REQUIRED
CONFIG
PATHS
${SUNDIALS_DIR}
${SUNDIALS_DIR}/lib/cmake/sundials)
message(STATUS "SUNDIALS configuration found: ${SUNDIALS_CONFIG}")
if(TARGET SUNDIALS::sunlinsolklu)
set(GRIDKIT_ENABLE_SUNDIALS_SPARSE ON CACHE INTERNAL BOOL "Sparse solver enabled in SUNDIALS.")
set(GRIDKIT_ENABLE_SUNDIALS_SPARSE
ON
CACHE INTERNAL BOOL "Sparse solver enabled in SUNDIALS.")
message(STATUS "KLU support enabled in SUNDIALS.")
endif()
endif()
Expand Down Expand Up @@ -125,27 +153,24 @@ add_subdirectory(docs)
export(EXPORT gridkit-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/GridKitTargets.cmake)

# Configuring exporting cmake config
install(EXPORT gridkit-targets
install(
EXPORT gridkit-targets
FILE GridKitTargets.cmake
NAMESPACE GridKit::
DESTINATION share/cmake/gridkit)

include(CMakePackageConfigHelpers)

# Basic version file
write_basic_package_version_file(
GridKitConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
write_basic_package_version_file(GridKitConfigVersion.cmake COMPATIBILITY SameMajorVersion)

# Generate config file that includes exports
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake
INSTALL_DESTINATION share/cmake/gridkit
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)

# Install configuration file
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfigVersion.cmake
DESTINATION share/cmake/gridkit)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfigVersion.cmake
DESTINATION share/cmake/gridkit)
11 changes: 3 additions & 8 deletions GridKit/AutomaticDifferentiation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

install(
FILES
DependencyTracking/Variable.hpp
DependencyTracking/VariableImplementation.hpp
DependencyTracking/VariableOperators.hpp
DESTINATION
include/GridKit/AutomaticDifferentiation/DependencyTracking)
install(FILES DependencyTracking/Variable.hpp DependencyTracking/VariableImplementation.hpp
DependencyTracking/VariableOperators.hpp
DESTINATION include/GridKit/AutomaticDifferentiation/DependencyTracking)
22 changes: 7 additions & 15 deletions GridKit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Definitions.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/Definitions.hpp)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Definitions.hpp
DESTINATION include/GridKit)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Definitions.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/Definitions.hpp)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Definitions.hpp DESTINATION include/GridKit)
add_library(definitions INTERFACE)
target_include_directories(definitions INTERFACE
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(
definitions
INTERFACE $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:include>)
add_library(GridKit::definitions ALIAS definitions)
install(TARGETS definitions EXPORT gridkit-targets)

Expand All @@ -28,10 +26,4 @@ add_subdirectory(Solver)
# Testing library
add_subdirectory(Testing)

install(
FILES
Constants.hpp
CommonMath.hpp
ScalarTraits.hpp
DESTINATION
include/GridKit)
install(FILES Constants.hpp CommonMath.hpp ScalarTraits.hpp DESTINATION include/GridKit)
7 changes: 1 addition & 6 deletions GridKit/LinearAlgebra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

add_subdirectory(SparseMatrix)
add_subdirectory(DenseMatrix)

install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/MemoryUtils.hpp
DESTINATION
include/GridKit/LinearAlgebra)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/MemoryUtils.hpp DESTINATION include/GridKit/LinearAlgebra)
11 changes: 4 additions & 7 deletions GridKit/LinearAlgebra/DenseMatrix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

add_library(DenseMatrix INTERFACE)
target_include_directories(DenseMatrix INTERFACE ${CMAKE_SOURCE_DIR})
target_include_directories(
DenseMatrix
INTERFACE ${CMAKE_SOURCE_DIR})

add_library(GridKit::DenseMatrix ALIAS DenseMatrix)

install(
FILES
DenseMatrix.hpp
DESTINATION
include/GridKit/LinearAlgebra/DenseMatrix)
install(FILES DenseMatrix.hpp DESTINATION include/GridKit/LinearAlgebra/DenseMatrix)
12 changes: 4 additions & 8 deletions GridKit/LinearAlgebra/SparseMatrix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
gridkit_add_library(sparse_matrix
SOURCES
CooMatrix.cpp
CsrMatrix.cpp
HEADERS
COO_Matrix.hpp
CooMatrix.hpp
CsrMatrix.hpp)
gridkit_add_library(
sparse_matrix
SOURCES CooMatrix.cpp CsrMatrix.cpp
HEADERS COO_Matrix.hpp CooMatrix.hpp CsrMatrix.hpp)
7 changes: 2 additions & 5 deletions GridKit/Model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ add_subdirectory(PhasorDynamics)
add_subdirectory(PowerFlow)
add_subdirectory(PowerElectronics)

install(FILES
Evaluator.hpp
VariableMonitor.hpp
VariableMonitorController.hpp
DESTINATION include/GridKit/Model)
install(FILES Evaluator.hpp VariableMonitor.hpp VariableMonitorController.hpp
DESTINATION include/GridKit/Model)
Loading