Skip to content

Commit

Permalink
Start modernising
Browse files Browse the repository at this point in the history
This commit starts to modernise the cmake, add a DevContainer and fix some warnings.
  • Loading branch information
Gerharddc committed Nov 22, 2024
1 parent 6dff0c0 commit 02385b4
Show file tree
Hide file tree
Showing 33 changed files with 235 additions and 580 deletions.
26 changes: 26 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:noble

# Update system
RUN apt-get update -y && apt-get upgrade -y

# Install dependencies for Sparselizard
RUN apt-get install -y \
clang clang-format cmake zsh git curl \
libopenblas-dev \
libopenmpi-dev \
libmumps-dev \
libmetis-dev \
petsc-dev \
slepc-dev \
libgmsh-dev \
libomp-dev

# Fix git issues with the container running as root
RUN git config --global --add safe.directory '*'

# Install Oh My Zsh for convenience
RUN chsh -s $(which zsh)
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" || true

# Set the default shell to Zsh
CMD ["zsh"]
14 changes: 14 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools-extension-pack",
"DavidAnson.vscode-markdownlint",
"ms-azuretools.vscode-docker"
]
}
}
}
124 changes: 96 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,111 @@
# Thanks to S. Matsievskiy for bringing cmake to the project.

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)

project(Sparselizard LANGUAGES CXX)

set(DEFAULT_BUILD_TYPE "Release")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build" FORCE)

set(PETSC_PATH "~/SLlibs/petsc" CACHE STRING "Provide the path to the petsc folder")
set(GMSH_PATH "~/SLlibs/gmsh" CACHE STRING "Provide the path to the gmsh folder")
set(MPI_PATH "" CACHE STRING "Provide the path to the mpi folder")

# Place library in build folder:
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Og -Wall -Wextra -Wpedantic")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")

# TODO: get this working
#set(CMAKE_CXX_COMPILER "clang++")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")

if(NOT BLA_VENDOR)
set(BLA_VENDOR CACHE STRING OpenBLAS)
endif()

# Default flags:
set(BLAS_FOUND NO)
set(GMSH_FOUND NO)
set(METIS_FOUND NO)
set(MPI_FOUND NO)
set(MUMPS_FOUND NO)
set(PETSC_FOUND NO)
set(SLEPC_FOUND NO)
if(NOT PETSC_DIR AND NOT(APPLE))
set(PETSC_DIR CACHE STRING /usr/lib/petscdir)
endif()

# Add cmake packages
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_PREFIX_PATH $<$<BOOL:${APPLE}>:/opt/homebrew/opt/openblas> ${PETSC_DIR})

# Installation definitions
include(GNUInstallDirs)
# Aux functions
include(cMake/functions.cmake)
include(cMake/SetupBLAS.cmake)
include(cMake/SetupGMSH.cmake)
include(cMake/SetupMETIS.cmake)
include(cMake/SetupMPI.cmake)
include(cMake/SetupMUMPS.cmake)
include(cMake/SetupPETSC.cmake)
include(cMake/SetupSLEPC.cmake)

# Add libsparselizard target
add_subdirectory(src)

# Add simulations targets
add_subdirectory(simulations)

# this is not the cmake-official way but it's a lot easier
set(INCLUDE_DIRS
src
src/mesh
src/gausspoint
src/io
src/io/paraview
src/io/nastran
src/io/gmsh
src/field
src/resolution
src/geometry
src/expression
src/expression/operation
src/shapefunction
src/shapefunction/hierarchical
src/shapefunction/hierarchical/h1
src/shapefunction/hierarchical/hcurl
src/shapefunction/lagrange
src/formulation
)
file(GLOB_RECURSE SRC_FILES "src/*.cpp")
file(GLOB_RECURSE SRC_HEADERS "src/*.h")
add_library(sparselizard SHARED ${SRC_FILES})
# Note: the following would allow hierarchical install, but sparselizard acts as if it's flattened
# target_sources(sparselizard PUBLIC FILE_SET HEADERS FILES ${SRC_HEADERS} BASE_DIRS src)
target_precompile_headers(sparselizard PUBLIC ${SRC_HEADERS})
target_include_directories(sparselizard PUBLIC ${INCLUDE_DIRS})
set_target_properties(sparselizard PROPERTIES PUBLIC_HEADER "${SRC_HEADERS}")

target_compile_options(sparselizard PUBLIC -fPIC -O3)

find_package(OpenMP REQUIRED)
target_link_libraries(sparselizard PUBLIC OpenMP::OpenMP_CXX)

find_package(MPI REQUIRED)
target_link_libraries(sparselizard PUBLIC MPI::MPI_CXX)

find_package(BLAS REQUIRED)
target_link_libraries(sparselizard PUBLIC BLAS::BLAS)

find_package(PETSC REQUIRED)
target_link_libraries(sparselizard PUBLIC PETSC::PETSC)

find_package(SLEPC)
target_link_libraries(sparselizard PUBLIC SLEPC::SLEPC)

find_package(GMSH)
if(GMSH_FOUND)
target_link_libraries(sparselizard PUBLIC GMSH::GMSH)
target_compile_definitions(sparselizard PRIVATE -DHAVE_GMSH)
endif()

find_package(METIS)

if(METIS_FOUND)
target_link_libraries(sparselizard PUBLIC METIS::METIS)
target_compile_definitions(sparselizard PRIVATE -DHAVE_METIS)
endif()

target_link_libraries(sparselizard PUBLIC cmumps)
target_compile_definitions(sparselizard PRIVATE
-DHAVE_BLAS
-DHAVE_MPI
-DHAVE_MUMPS
-DHAVE_PETSC
-DHAVE_SLEPC
)

install(TARGETS sparselizard LIBRARY PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/sparselizard)

set(BUILD_SIMULATIONS YES)

if(BUILD_SIMULATIONS)
add_subdirectory(simulations)
message(STATUS "Building simulations")
endif()
72 changes: 0 additions & 72 deletions Makefile

This file was deleted.

47 changes: 0 additions & 47 deletions cMake/SetupBLAS.cmake

This file was deleted.

43 changes: 0 additions & 43 deletions cMake/SetupGMSH.cmake

This file was deleted.

47 changes: 0 additions & 47 deletions cMake/SetupMETIS.cmake

This file was deleted.

Loading

0 comments on commit 02385b4

Please sign in to comment.