Skip to content

Commit

Permalink
Fixes to case of VTK identifiers (#63)
Browse files Browse the repository at this point in the history
* WIP: Travis CI updates

* WIP: updates

* Revert gfortran-9 to 8 w/ linux bionic

* Fix line cnt

* Remove redundant submodule use statements

* Re-use gcc-9 w/ linux TRAVIS-CI

* README updates

* WIP: cmake updates for MSVS, platform abstraction

* Capitalization fix

* Added ability to specify encoding

* case fixes to legacy vtk writes

* Modern VTK case fixes

* travis-ci fix for updated cmake
  • Loading branch information
porteri authored Nov 22, 2019
1 parent 6653e2e commit 8108d44
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 238 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ matrix:
env: GCC=8
before_install:
- brew install gcc@8
- brew upgrade cmake
- export FC=gfortran-${GCC}
- cmake --version
- os: osx
osx_image: xcode10
env: GCC=9
before_install:
- brew install gcc@9
- brew upgrade cmake
- export FC=gfortran-${GCC}
- cmake --version
- os: osx
Expand Down
146 changes: 56 additions & 90 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
cmake_minimum_required(VERSION 3.13.4)

option(VTKmofo_USE_OpenCoarrays
"Build VTKmofo with support for linking against OpenCoarray programs" OFF)
"Build vtkmofo with support for linking against OpenCoarray programs" OFF)

# Project name
project(vtkmofo LANGUAGES Fortran)

# vtkmofo project version
set (VTKMOFO_VERSION_MAJOR 1)
set (VTKMOFO_VERSION_MINOR 100)
set(VTKMOFO_VERSION_MAJOR 1)
set(VTKMOFO_VERSION_MINOR 200)

# Custom modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
include(Platform_Compiler_Options) # Performs abstraction for OS and compiler options
include(AddLibFunction)

# Print project logo, version and tag line
file(READ ${CMAKE_CURRENT_LIST_DIR}/cmake/VTKMOFO-logo.txt VTKMOFO_LOGO)
Expand All @@ -27,126 +32,89 @@ message(STATUS "${VTKMOFO_GREETING}")
# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# System options
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
set(prefix "/")
set(infix ":")
set(Qf "Q")
set(Q "Q")
set(eq ":")
set(colon ":")
set(colon_ ":")
set(libs_static "/libs:static")
set(dgblibs "/dbglibs")
else()
set(prefix "-")
set( infix " ")
set( Qf "f")
set( Q "")
set( eq "=")
set( colon "")
set( colon_ " ")
set( libs_static "")
set( dgblibs "")
endif()

# Compiler options
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel")
set(intel_compiler true)
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
# Full debug, Fortran 2008 standard, free format (due to automatic build to .f file for testing), Check bounds
set(CMAKE_Fortran_FLAGS
"${prefix}nologo ${prefix}debug${infix}full ${prefix}MP ${prefix}Od ${prefix}standard-semantics ${prefix}warn${infix}errors ${prefix}stand${infix}f15 ${prefix}debug-parameters${infix}all ${prefix}warn${infix}declarations ${prefix}warn${infix}unused ${prefix}warn${infix}interfaces ${prefix}${Qf}trapuv ${prefix}${Q}init${eq}snan ${prefix}${Q}init${eq}arrays ${prefix}fpe${colon}0 ${prefix}traceback ${prefix}check${colon_}bounds ${prefix}check${colon_}stack ${libs_static} ${prefix}threads ${dbglibs} ${prefix}free"
)
else()
# Full debug, Fortran 2008 standard, free format (due to automatic build to .f file for testing), Check bounds
set(CMAKE_Fortran_FLAGS
"${prefix}nologo ${prefix}debug${infix}full ${prefix}multiple-processes ${prefix}O0 ${prefix}standard-semantics ${prefix}warn${infix}errors ${prefix}stand${infix}f15 ${prefix}debug-parameters${infix}all ${prefix}warn${infix}declarations ${prefix}warn${infix}unused ${prefix}warn${infix}interfaces ${prefix}${Qf}trapuv ${prefix}${Q}init${eq}snan ${prefix}${Q}init${eq}arrays ${prefix}fpe${colon}0 ${prefix}traceback ${prefix}check${colon_}bounds ${prefix}check${colon_}stack ${libs_static} ${prefix}threads ${dbglibs} ${prefix}free"
)
endif()
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
set(gnu_compiler true)
# Fortran 2008 standard, free format (due to automatic build to .f file for testing)
set(CMAKE_Fortran_FLAGS "${prefix}std=f2008 ${prefix}fcheck=all ${prefix}Wall ${prefix}Wno-unused-dummy-argument ${prefix}ffree-form -fbacktrace")
else()
message(WARNING
"\n"
"Attempting to build with untested Fortran compiler: ${CMAKE_Fortran_COMPILER_ID}. "
"Please report any failures through the vtkmofo Git issues\n\n"
)
endif()

if(VTKmofo_USE_OpenCoarrays)
find_package(OpenCoarrays)
endif()

##################################################
# Begin VTKmofo specific targets and configuration
# Begin vtkmofo specific targets and configuration
##################################################

# Where to put VTKmofo module files
# Where to put vtkmofo module files
set(VTKmofo_mod_dir ${CMAKE_CURRENT_BINARY_DIR}/mod)

# Avoid compilation cascades:
# put interfaces and submodules in separate libraries
# Specify VTKmofo interfaces
set(VTKmofo_interfaces
# Utilities
set(vtkmofo_utilities
utilities/File_utility.f90
utilities/File_utility_procedures.f90
# utilities/Linked_list.f90
# utilities/Linked_list_procedures.f90
utilities/Misc.f90
utilities/Misc_procedures.f90
utilities/Precision.f90
utilities/XML.f90
utilities/XML_procedures.f90
)

# Legacy vtk files
set(vtkmofo_legacy
legacy/VTK_io.f90
legacy/VTK_datasets.f90
legacy/VTK_cells.f90
legacy/VTK_attributes.f90
legacy/VTK_vars.f90
modern/VTK_DataArray.f90
modern/VTK_element.f90
modern/VTK_formats_types.f90
modern/VTK_piece_element.f90
modern/VTK_serial_file.f90
modern/VTK_serial_Grid.f90
)

# Specify VTKmofo implementations
set(VTKmofo_procedures
utilities/File_utility_procedures.f90
# utilities/Linked_list_procedures.f90
utilities/Misc_procedures.f90
utilities/XML_procedures.f90
legacy/VTK_attributes_procedures.f90
legacy/VTK_cells_procedures.f90
legacy/VTK_datasets_procedures.f90
legacy/VTK.f90
legacy/VTK_io_procedures.f90
)

# Modern vtk serial format files
set(vtkmofo_modern
modern/VTK_DataArray_procedures.f90
modern/VTK_element_procedures.f90
modern/VTK_piece_element_procedures.f90
modern/VTK_serial_file_procedures.f90
modern/VTK_serial_Grid_procedures.f90
modern/VTK_DataArray.f90
modern/VTK_element.f90
modern/VTK_formats_types.f90
modern/VTK_piece_element.f90
modern/VTK_serial_file.f90
modern/VTK_serial_Grid.f90
)

# Compile all the interfaces first
foreach(item ${VTKmofo_interfaces})
list(APPEND VTKmofo_interface_srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/${item}")
# Compile the utilities library first
foreach(item ${vtkmofo_utilities})
list(APPEND vtkmofo_utilities_srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/${item}")
endforeach()
add_library(vtkmofo_interfaces OBJECT ${VTKmofo_interface_srcs})
add_library(vtkmofo_utilities OBJECT ${vtkmofo_utilities_srcs})
# Tell CMake where to put vtkmofo .mod files generated with libvtkmofo
set_property(TARGET vtkmofo_interfaces
PROPERTY
Fortran_MODULE_DIRECTORY ${VTKmofo_mod_dir})
set_property(TARGET vtkmofo_utilities
PROPERTY Fortran_MODULE_DIRECTORY ${VTKmofo_mod_dir})
# Visual Studio Organization
set_property(TARGET vtkmofo_utilities
PROPERTY FOLDER "source")
set_target_properties(vtkmofo_utilities
PROPERTIES PROJECT_LABEL "utilities")
# Link against OpenCoarrays (if needed)
if(VTKmofo_USE_OpenCoarrays)
target_link_libraries(vtkmofo_interfaces
target_link_libraries(vtkmofo_utilities
PRIVATE OpenCoarrays::caf_mpi_static)
endif()

# Add any object files from the interfaces to the main library build
foreach(item ${VTKmofo_procedures})
list(APPEND VTKmofo_procedures_srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/${item}")
foreach(item ${vtkmofo_legacy})
list(APPEND vtkmofo_srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/${item}")
endforeach()
foreach(item ${vtkmofo_modern})
list(APPEND vtkmofo_srcs "${CMAKE_CURRENT_SOURCE_DIR}/src/${item}")
endforeach()

add_library(vtkmofo
STATIC ${VTKmofo_procedures_srcs} $<TARGET_OBJECTS:vtkmofo_interfaces>)
STATIC ${vtkmofo_srcs} $<TARGET_OBJECTS:vtkmofo_utilities>)
# Link against OpenCoarrays (if needed)
if(VTKmofo_USE_OpenCoarrays)
target_link_libraries(vtkmofo
PRIVATE OpenCoarrays::caf_mpi_static)
Expand All @@ -165,7 +133,6 @@ if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
)
endif()


# Tell CMake where to put vtkmofo .mod files generated with libvtkmofo
set_property(TARGET vtkmofo
PROPERTY
Expand All @@ -181,7 +148,7 @@ target_include_directories(vtkmofo PUBLIC
source_group("VTKmofoLib" FILES ${VTKmofo_sources})
set_property(TARGET vtkmofo
PROPERTY
FOLDER "VTKmofo")
FOLDER "source")
install(TARGETS vtkmofo DESTINATION lib EXPORT vtkmofo-targets)
# Breaking this code out into a function would be nice
set(MOD_DIR_TO_INSTALL "${VTKmofo_mod_dir}")
Expand All @@ -194,8 +161,6 @@ install(
)
install(EXPORT vtkmofo-targets DESTINATION lib/vtkmofo)



######################
# Add test directories
######################
Expand All @@ -215,16 +180,17 @@ endforeach()
foreach(unit_test ${VTKmofo_unit_test_list})
add_test(NAME "VTKmofo_${unit_test}_test" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unit/${unit_test} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests/unit)
set_property(TEST "VTKmofo_${unit_test}_test" PROPERTY PASS_REGULAR_EXPRESSION "Test Passed")
set_property(TEST "VTKmofo_${unit_test}_test" PROPERTY LABELS "VTKmofo" "unit-test")
set_property(TEST "VTKmofo_${unit_test}_test" PROPERTY LABELS "vtkmofo" "unit-test")
endforeach()

# Add integration tests and define the string that is used to signal success
foreach(integration_test ${VTKmofo_integration_test_list})
add_test(NAME "VTKmofo_${integration_test}_test" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/integration/${integration_test} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests/integration)
set_property(TEST "VTKmofo_${integration_test}_test" PROPERTY PASS_REGULAR_EXPRESSION "Finished")
set_property(TEST "VTKmofo_${integration_test}_test" PROPERTY LABELS "VTKmofo" "integration-test")
set_property(TEST "VTKmofo_${integration_test}_test" PROPERTY LABELS "vtkmofo" "integration-test")
set_property(TEST "VTKmofo_${integration_test}_test" PROPERTY FOLDER "VTKMOFO_Integration_Tests")
endforeach()

add_custom_target(RUN_ALL_VTKmofo_TESTS
COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> --output-on-failure -L "VTKmofo")
COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> --output-on-failure -L "vtkmofo")
set_property(TARGET RUN_ALL_VTKmofo_TESTS PROPERTY FOLDER "All-Tests")
77 changes: 77 additions & 0 deletions cmake/modules/AddLibFunction.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Functions to abstract common tasks for creating and manipulating targets & tests
include_guard(DIRECTORY) # Check to see if the file has previously been processed
# Create a function to generate libraries from lists of source files
# given relative to the current CMakeLists.txt
#
# Mandatory arguments:
#
# Positional argument 1: lib_name
# Name of library to create (without leading "lib")
# Keyword Argument SOURCES:
# A list of source files relative to ${CMAKE_CURRENT_SOURCE_DIR} to compile
#
# Optional keyword arguments:
# LINKAGE: Allowed values are STATIC, SHARED, MODULE. Not passing a value
# defaults to CMake's default behavior. (BUILD_SHARED_LIBS can override
# CMakes default behavior but LINKAGE specified here takes precedence.
# set LIB_FORCE_LINKAGE=(STATIC | SHARED | MODULE) to override.)
# INSTALL_DEST: Subdirectory install location. Defaults to "lib".

function(add_lib lib_name)
# Parse arguments
set(options "")
set(oneValueArgs LINKAGE INSTALL_DEST)
set(multiValueArgs SOURCES)
cmake_parse_arguments(add_lib "${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN})
if(NOT add_lib_SOURCES)
message( FATAL_ERROR "Argument 'SOURCES' to add_lib() CMake function is mandatory!
Please pass the source file names (relative to the ${CMAKE_CURRENT_SOURCE_DIR}).")
endif()

# Add each source file (with path) to list
foreach(src IN LISTS add_lib_SOURCES)
list(APPEND ${lib_name}Sources "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
endforeach()

# Determine linkage if specified; default to system default behavior
# See CMake documentation for BUILD_SHARED_LIBS variable
set(ALLOWED_LINKAGE STATIC SHARED MODULE)
if(add_lib_LINKAGE)
if(NOT ${add_lib_LINKAGE} IN_LIST ALLOWED_LINKAGE)
message( FATAL_ERROR "Argument 'LINKAGE' passed to add_lib() must be one of:
STATIC, SHARED, or MODULE to match valid options passed to add_library()")
else()
set(LINKAGE ${add_lib_LINKAGE})
endif()
endif()

if(LIB_FORCE_LINKAGE)
if(NOT ${LIB_FORCE_LINKAGE} IN_LIST ALLOWED_LINKAGE)
message( FATAL_ERROR "'LIB_FORCE_LINKAGE' must be one of:
STATIC, SHARED, or MODULE to match valid options passed to add_library()")
else()
set(LINKAGE ${LIB_FORCE_LINKAGE})
endif()
endif()

# Add library target using info processed so far
add_library(${lib_name} ${LINKAGE}
${${lib_name}Sources})

get_target_property(LNK_LANG ${lib_name} LINKER_LANGUAGE)
if(NOT ${LINKER_LANGUAGE} STREQUAL C)
target_compile_options(${lib_name} BEFORE
PRIVATE ${prefix}warn${infix}errors)
if(TARGET OpenCoarrays::caf_mpi_static)
target_link_libraries(${lib_name}
PUBLIC OpenCoarrays::caf_mpi_static)
endif()
endif()

# Tell CMake where to install it
set(_INSTALL_DEST "lib")
if(add_lib_INSTALL_DEST)
set(_INSTALL_DEST ${add_lib_INSTALL_DEST})
endif()
endfunction(add_lib)
53 changes: 53 additions & 0 deletions cmake/modules/Platform_Compiler_Options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This function handles the compiler and platform options
# for the following compilers:
# 1) gfortran
# 2) intel (not implemented / testted as part of this project)
#
set(CMAKE_VERBOSE_MAKEFILE OFF)
include_guard(DIRECTORY) # Check to see if the file has previously been processed

# Compiler options
if (CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
# Intel platform specific settings
if (WIN32) # Windows options
set(prefix "/")
set(infix ":")
set(Qf "Q")
set(Q "Q")
set(eq ":")
set(colon ":")
set(colon_ ":")
set(libs_static "/libs:static")
set(dbglibs "/dbglibs")
else() # *nix options
set(prefix "-")
set(infix " ")
set(Qf "f")
set(Q "")
set(eq "=")
set(colon "")
set(colon_ " ")
set(libs_static "")
set(dbglibs "")
endif()

set(Intel_Fortran_FLAGS_Release "${prefix}check${colon_}none ${prefix}O3")
set(Intel_Fortran_FLAGS_Debug "${prefix}check${colon_}all ${prefix}O0")

# "${prefix}nologo ${prefix}debug${infix}full ${prefix}MP ${prefix}Od ${prefix}standard-semantics ${prefix}warn${infix}errors ${prefix}stand${infix}f15 ${prefix}debug-parameters${infix}all ${prefix}warn${infix}declarations ${prefix}warn${infix}unused ${prefix}warn${infix}interfaces ${prefix}${Qf}trapuv ${prefix}${Q}init${eq}snan ${prefix}${Q}init${eq}arrays ${prefix}fpe${colon}0 ${prefix}traceback ${prefix}check${colon_}bounds ${prefix}check${colon_}stack ${libs_static} ${prefix}threads ${dbglibs} ${prefix}free"
# "${prefix}nologo ${prefix}debug${infix}full ${prefix}multiple-processes ${prefix}O0 ${prefix}standard-semantics ${prefix}warn${infix}errors ${prefix}stand${infix}f15 ${prefix}debug-parameters${infix}all ${prefix}warn${infix}declarations ${prefix}warn${infix}unused ${prefix}warn${infix}interfaces ${prefix}${Qf}trapuv ${prefix}${Q}init${eq}snan ${prefix}${Q}init${eq}arrays ${prefix}fpe${colon}0 ${prefix}traceback ${prefix}check${colon_}bounds ${prefix}check${colon_}stack ${libs_static} ${prefix}threads ${dbglibs} ${prefix}free"

set(Intel_EXE_LINKER_FLAGS "${prefix}traceback ${prefix}stand${colon_}f15 ${prefix}${Q}coarray${colon_}distributed")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
# GFortran build configs
set(GNU_Fortran_FLAGS_Release "-fbacktrace -std=f2018 -ffree-form -fcheck=all")
set(GNU_Fortran_FLAGS_Debug "-fbacktrace -std=f2018 -ffree-form")
else()
message(WARNING
"\n"
"Attempting to build with untested Fortran compiler: ${CMAKE_Fortran_COMPILER_ID}. "
"Please report any failures through the vtkmofo Git issues\n\n"
)
endif()

list(JOIN ${CMAKE_Fortran_COMPILER_ID}_Fortran_FLAGS_${CMAKE_BUILD_TYPE} " " CMAKE_Fortran_FLAGS)
Loading

0 comments on commit 8108d44

Please sign in to comment.