Skip to content

Commit

Permalink
UGRID-14, UGRID-16, UGRID-17, UGRID-19: Pitchfork layout (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-el-sayed authored Aug 14, 2024
1 parent e7d803f commit 169cdaf
Show file tree
Hide file tree
Showing 56 changed files with 713 additions and 441 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:

# Step: Test
- name: Test
run: ${{ steps.paths.outputs.build_dir }}/bin/UGridApiTests
run: ${{ steps.paths.outputs.build_dir }}/tests/api/UGridAPITests

# Step: Install
- name: Install
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/style-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ jobs:

- name: Run clang-format and report result
run: |
declare -a directories=("src" "include" "tests")
declare -a directories=(
"libs/UGrid/src"
"libs/UGrid/include"
"libs/UGridAPI/src"
"libs/UGridAPI/include"
"tests"
)
# Parse full lines
export IFS=$'\n'
for directory in "${directories[@]}"; do
Expand Down
174 changes: 44 additions & 130 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,130 +1,44 @@
# Works with 3.14 and tested through 3.18
cmake_minimum_required(VERSION 3.16...3.18)

# Set compiler flags
enable_language(C CXX)

option(PRODUCE_CODE_COVERAGE "Produce code coverage files under GNU compilers" OFF)

# Project name and a few useful settings. Other commands can pick up the results
project(
UGrid
VERSION 0.0.0
DESCRIPTION "Library for reading/writing UGrid files."
LANGUAGES CXX C)

# Make sure all executables and shared libraries end up in one directory,
# otherwise the executables won't run under Windows. This will cause
# the build to fail.
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")

# Create position independent binaries
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Require C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Disable compiler specific extensions
set(CMAKE_CXX_EXTENSIONS OFF)
# Set cmake installation prefix, so UGrid library gets installed under /UGrid
SET(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/UGrid")

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O2 -std=c++17 -Werror -Wall -Wextra -pedantic -Wno-unused-function")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -std=c++17")
else()
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} /EHsc /MP /std:c++17")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHsc /MP /std:c++17")
endif()

# Create position independent binaries
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Disable compiler specific extensions
set(CMAKE_CXX_EXTENSIONS OFF)

# Let's nicely support folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Note this needs to be done in the main CMakeLists since it calls
# enable_testing, which must be in the main CMakeLists.

include(FetchContent)
set(FETCHCONTENT_QUIET off)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.13.0
)
if(WIN32)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

include(CTest)

# Docs only available if this is the main app
add_subdirectory(docs)

endif()

# Determine version suffix from environment variable
if(DEFINED ENV{VERSION_SUFFIX})
set(VERSION_SUFFIX $ENV{VERSION_SUFFIX})
else()
set(VERSION_SUFFIX .0)
endif()

# Boost
if(WIN32)
# In windows use static libraries
set(Boost_USE_STATIC_LIBS ON)
endif()
find_package(Boost REQUIRED COMPONENTS system filesystem)
include_directories(${Boost_INCLUDE_DIR})

# Use NetCDF
find_package(netCDF REQUIRED COMPONENTS C)
if (netCDF_FOUND)
message(STATUS "Found NetCDF ${netCDF_VERSION}")
else()
message(FATAL_ERROR "Could not find NetCDF" )
endif()

# Use NetCDF-cxx
find_package(netCDFCxx REQUIRED)
if (netCDFCxx_FOUND)
message(STATUS "Found NetCDFCxx ${netCDFCxx_VERSION}")
else()
message(FATAL_ERROR "Could not find NetCDFCxx")
endif()

find_package(hdf5 REQUIRED)
if (hdf5_FOUND)
message(STATUS "Found HDF5 ${hdf5_VERSION}")
endif()

# Run packaging scripts
add_subdirectory(package)

# The version file
add_subdirectory(include/Version)

# The static library
add_subdirectory(src/UGrid)

# The dynamic library
add_subdirectory(src/UGridApi)

# Testing only available if this is the main app.
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_subdirectory(tests)
endif()
cmake_minimum_required(VERSION 3.23)

set(UGRID_VERSION 0.0.0)

project(
UGrid
VERSION ${UGRID_VERSION}
DESCRIPTION "Library for reading and writing UGrid files."
LANGUAGES CXX C
)

# configuration options
if (NOT WIN32)
message(NOTICE "Build type: ${CMAKE_BUILD_TYPE}")
endif()

# configuration options
include(cmake/user_config_options.cmake)

# configure the compiler
include(cmake/compiler_config.cmake)

# fetch dependencies, must appear after options.cmake
include(cmake/fetch_contents.cmake)

# find required packages
include(cmake/find_packages.cmake)

# organize targets into folders, can be remove in version > 3.26 (ON by default)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Docs only available if this is the main app
add_subdirectory(docs)

# Run packaging scripts: requires semantic version
add_subdirectory(package)

# Libraries
add_subdirectory(libs)

# Add unit tests
if(ENABLE_UNIT_TESTING)
add_subdirectory(tests)
endif()
32 changes: 32 additions & 0 deletions cmake/compiler_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Set the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Disable compiler-specific extensions
set(CMAKE_CXX_EXTENSIONS OFF)

# Create position-independent executables and shared libraries
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Add compiler-specific options and definitions per supported platform
if (UNIX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options("-fvisibility=hidden;-Werror;-Wall;-Wextra;-pedantic;-Wno-unused-function")
add_compile_options("$<$<CONFIG:RELEASE>:-O2>")
add_compile_options("$<$<CONFIG:DEBUG>:-g>")
else()
message(FATAL_ERROR "Unsupported compiler. Only GNU is supported under Linux. Found ${CMAKE_CXX_COMPILER_ID}.")
endif()
elseif(WIN32)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options("/EHsc;/MP;/W3;/WX")
add_compile_options("$<$<CONFIG:RELEASE>:/O2>")
add_compile_options("$<$<CONFIG:DEBUG>:/Od;/DEBUG>")
add_compile_definitions("_USE_MATH_DEFINES")
add_compile_definitions("_CRT_SECURE_NO_WARNINGS")
else()
message(FATAL_ERROR "Unsupported compiler. Only MSVC is supported under Windows. Found ${CMAKE_CXX_COMPILER_ID}.")
endif()
else()
message(FATAL_ERROR "Unsupported platform. Only Linux and Windows are supported.")
endif()
23 changes: 23 additions & 0 deletions cmake/fetch_contents.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include(FetchContent)
set(FETCHCONTENT_QUIET off)

if(ENABLE_UNIT_TESTING)
# Fetch google test
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.13.0
)

if(WIN32)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

include(CTest)
endif()
28 changes: 28 additions & 0 deletions cmake/find_packages.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Boost
set(BOOST_MIN_REQ_VERSION "1.78.0")
find_package(Boost ${BOOST_MIN_REQ_VERSION} REQUIRED)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Could not find Boost (minimum required version is ${BOOST_MIN_REQ_VERSION})")
endif()

# netCDF
find_package(netCDF REQUIRED COMPONENTS C)
if (netCDF_FOUND)
message(STATUS "Found NetCDF ${netCDF_VERSION}")
else()
message(FATAL_ERROR "Could not find NetCDF" )
endif()

# netCDFCxx
find_package(netCDFCxx REQUIRED)
if (netCDFCxx_FOUND)
message(STATUS "Found NetCDFCxx ${netCDFCxx_VERSION}")
else()
message(FATAL_ERROR "Could not find NetCDFCxx")
endif()

# hdf5
find_package(hdf5 REQUIRED)
if (hdf5_FOUND)
message(STATUS "Found HDF5 ${hdf5_VERSION}")
endif()
15 changes: 15 additions & 0 deletions cmake/user_config_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# unit testing option
option(
ENABLE_UNIT_TESTING
"Enables building the unit test executables"
ON
)

# code coverage option
if(LINUX AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
option(
ENABLE_CODE_COVERAGE
"Generates code coverage statistics."
OFF
)
endif()
10 changes: 5 additions & 5 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ endif()

set(DOXYGEN_INPUT_LIST
"${CMAKE_CURRENT_SOURCE_DIR}/main_page.md \
${PROJECT_SOURCE_DIR}/include/UGrid \
${PROJECT_SOURCE_DIR}/include/UGridApi")
${PROJECT_SOURCE_DIR}/libs/UGrid/include/UGrid \
${PROJECT_SOURCE_DIR}/libs/UGridAPI/include/UGridAPI")
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/html/index.html)
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
Expand All @@ -25,11 +25,11 @@ file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR})

# UGrid headers
file(GLOB UGrid_HEADER_LIST CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/include/UGrid/*.hpp")
"${PROJECT_SOURCE_DIR}/libs/UGrid/include/UGrid/*.hpp")

# UGridapi headers
file(GLOB UGridAPI_HEADER_LIST CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/include/UGridApi/*.hpp")
"${PROJECT_SOURCE_DIR}/libs/UGridAPI/include/UGridAPI/*.hpp")

# markdown file
file(GLOB DOXYGEN_MARKDOWN_FILES CONFIGURE_DEPENDS
Expand All @@ -41,7 +41,7 @@ add_custom_command(
DEPENDS ${UGrid_HEADER_LIST} ${UGridAPI_HEADER_LIST}
${DOXYGEN_MARKDOWN_FILES}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/include"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/libs"
MAIN_DEPENDENCY ${DOXYFILE_OUT}
${DOXYFILE_IN}
COMMENT "Generating docs")
Expand Down
3 changes: 0 additions & 3 deletions include/Version/CMakeLists.txt

This file was deleted.

5 changes: 5 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Add UGrid static lib
add_subdirectory(UGrid)

# Add UGridAPI dynamic lib
add_subdirectory(UGridAPI)
Loading

0 comments on commit 169cdaf

Please sign in to comment.