Skip to content

Commit

Permalink
Merge pull request #5 from jchristopherson/v1.4_Development
Browse files Browse the repository at this point in the history
V1.4 development
  • Loading branch information
jchristopherson authored Dec 7, 2022
2 parents e9a7359 + ddfe344 commit 1533e2c
Show file tree
Hide file tree
Showing 188 changed files with 19,407 additions and 5,692 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bin/
build/
latex/
lib/
mod/

# CMake Stuff
*.json
Expand Down
125 changes: 29 additions & 96 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,104 +1,35 @@
# CMake project file for FERROR
cmake_minimum_required(VERSION 3.0)
project(ferror C CXX Fortran)
cmake_minimum_required(VERSION 3.17)
project(
ferror
LANGUAGES
C
Fortran
VERSION "1.4.0"
)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
# Utilize the GNU installation structure
include(GNUInstallDirs)

# Define version information
set(FERROR_MAJOR_VERSION 1)
set(FERROR_MINOR_VERSION 3)
set(FERROR_PATCH_VERSION 1)
set(FERROR_VERSION ${FERROR_MAJOR_VERSION}.${FERROR_MINOR_VERSION}.${FERROR_PATCH_VERSION})
# Get the macros and functions we'll need
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")

# Set a default build type if none was specified
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)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()

# By default, shared library
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

# Export all symbols on Windows when building shared libraries
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

# Locate the module files
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_SOURCE_DIR}/include)

# Define output directories, if undefined
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
message(STATUS "FERROR output directories undefined. Using default directories.")
if (CMAKE_BUILD_TYPE MATCHES Debug)
# Debug Build
message(STATUS "FERROR: Debug Build")
if (BUILD_SHARED_LIBS)
message(STATUS "FERROR: Build shared library")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
else()
message(STATUS "FERROR: Build static library")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
endif ()
elseif (CMAKE_BUILD_TYPE MATCHES Release)
# Release Build
message(STATUS "FERROR: Release Build")
if (BUILD_SHARED_LIBS)
message(STATUS "FERROR: Build shared library")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Release)
else()
message(STATUS "FERROR: Build static library")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Release)
endif ()
else ()
# Default Condition
if (BUILD_SHARED_LIBS)
message(STATUS "FERROR: Build shared library")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/Debug)
else()
message(STATUS "FERROR: Build static library")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/Debug)
endif ()
endif ()
endif()

# FFLAGS depend on the compiler
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
if (Fortran_COMPILER_NAME MATCHES "gfortran.*")
# gfortran
# Options: https://gcc.gnu.org/onlinedocs/gfortran/Option-Summary.html
set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-all-loops -fno-f2c -O3")
set (CMAKE_Fortran_FLAGS_DEBUG "-fno-f2c -O0 -g -Wall")
elseif (Fortran_COMPILER_NAME MATCHES "ifort.*")
# ifort (untested)
set (CMAKE_Fortran_FLAGS_RELEASE "-f77rtl -O3")
set (CMAKE_Fortran_FLAGS_DEBUG "-f77rtl -O0 -g")
else()
message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER})
message ("Fortran compiler: " ${Fortran_COMPILER_NAME})
message ("No optimized Fortran compiler flags are known, we just try -O1...")
set (CMAKE_Fortran_FLAGS_RELEASE "-O1")
set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -Wall")
endif()

# Define the include directories
include_directories(${PROJECT_SOURCE_DIR}/include)
# Configure everything
add_subdirectory(configure)

# Build the library
add_subdirectory(src)
add_fortran_library(
${PROJECT_NAME}
${PROJECT_INCLUDE_DIR}
${CMAKE_INSTALL_INCLUDEDIR}
${PROJECT_VERSION}
${PROJECT_VERSION_MAJOR}
${FERROR_SOURCES}
)

# Install the library
add_subdirectory(install)

# ------------------------------------------------------------------------------
# EXAMPLES
Expand All @@ -116,11 +47,13 @@ endif()
# TESTS
# ------------------------------------------------------------------------------
# C Based Testing
option(BUILD_FERROR_TESTS "Build FERROR tests?" OFF)
if (BUILD_FERROR_TESTS)
option(BUILD_TESTING "Build tests")
if (BUILD_TESTING)
# Inform the user we're building the tests
message(STATUS "Building FERROR tests.")

# Build the tests
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ The error code is: 200
#include <stdio.h>
#include "ferror.h"

void causes_error(errorhandler *err);
void causes_error(error_handler *err);


int main(void) {
// Variables
errorhandler err_mgr;
error_handler err_mgr;
char fname[256], msg[256];
int flag, fnamelength = 256, msglength = 256;

// Initialization
alloc_errorhandler(&err_mgr);
alloc_error_handler(&err_mgr);

// Ensure the error reporting doesn't terminate the application
set_exit_on_error(&err_mgr, false);
Expand All @@ -93,12 +93,12 @@ int main(void) {
fname, msg, flag);

// End
free_errorhandler(&err_mgr);
free_error_handler(&err_mgr);
return 0;
}

void causes_error(errorhandler *err) {
report_error(err, // The errorhandler object
void causes_error(error_handler *err) {
report_error(err, // The error_handler object
"causes_error", // The function name
"This is a test error message.", // The error message
200); // The error flag
Expand All @@ -114,10 +114,7 @@ The error code is: 200
## Documentation
Documentation can be found [here](http://htmlpreview.github.io/?https://github.com/jchristopherson/ferror/blob/master/doc/html/index.html).

## Build Instructions
This library utilizes [CMake](https://cmake.org/) to facilitate its build. Using CMake is as simple as issuing the following commands.
- cmake ...
- make
- make install
## Compiling
[CMake](https://cmake.org/) is the preferred build system for this library. See [Running CMake](https://cmake.org/runningcmake/) for instructions on how to build using CMake.

See [Running CMake](https://cmake.org/runningcmake/) for more details on the use of CMake.
[Meson](https://mesonbuild.com/index.html) can also be used to build this library. See [this](https://mesonbuild.com/Quick-guide.html) quick start guid on how to use Meson.
69 changes: 69 additions & 0 deletions cmake/helper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# helper.cmake
#
# A collection of macros and functions making life with CMake and Fortran a
# bit simpler.

# Use to include and export headers
function(include_headers lib dir install_dir)
target_include_directories(
${lib}
INTERFACE
$<BUILD_INTERFACE:${dir}>
$<INSTALL_INTERFACE:${install_dir}>
)
endfunction()

# Use instead of add_library.
function(add_fortran_library lib_name mod_dir include_install_dir version major)
add_library(${lib_name} ${ARGN})
set_target_properties(
${lib_name}
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME ${lib_name}
VERSION ${version}
SOVERSION ${major}
Fortran_MODULE_DIRECTORY ${include_install_dir}
)
target_include_directories(
${lib_name}
PUBLIC
$<BUILD_INTERFACE:${mod_dir}>
$<INSTALL_INTERFACE:${include_install_dir}>
)
endfunction()

# Installs the library
function(install_library lib_name lib_install_dir bin_install_dir mod_dir install_dir)
install(
TARGETS ${lib_name}
EXPORT ${lib_name}Targets
RUNTIME DESTINATION ${bin_install_dir}
LIBRARY DESTINATION ${lib_install_dir}
ARCHIVE DESTINATION ${lib_install_dir}
INCLUDES DESTINATION ${install_dir}/include
)
install(
DIRECTORY ${mod_dir}
DESTINATION ${install_dir}
)
endfunction()

# Install the documentation files
function(install_documentation doc_dir install_dir)
install(
DIRECTORY ${doc_dir}
DESTINATION ${install_dir}
)
endfunction()

# ------------------------------------------------------------------------------
# Helpful Macros
macro(print_all_variables)
message(STATUS "---------- CURRENTLY DEFIND VARIABLES -----------")
get_cmake_property(varNames VARIABLES)
foreach(varName ${varNames})
message(STATUS ${varName} = ${${varName}})
endforeach()
message(STATUS "---------- END ----------")
endmacro()
24 changes: 24 additions & 0 deletions configure/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Get the macros and functions we'll need
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")

# Set a default build type if none was specified
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)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()

# By default, static library
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

# Export all symbols on Windows when building libraries
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

# Utilize the GNU installation structure
include(GNUInstallDirs)

# Locate the local include directory
set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(PROJECT_INCLUDE_DIR ${PROJECT_INCLUDE_DIR} PARENT_SCOPE)
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_INCLUDE_DIR})
Loading

0 comments on commit 1533e2c

Please sign in to comment.