Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt examples to cmake build system. #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# OpenCMISS (Open Continuum Mechanics, Imaging, Signal processing and System identification)
# is a mathematical modelling environment that enables the application of finite element
# analysis techniques to a variety of complex bioengineering problems.
#
# The OpenCMISS project website can be found at http://www.opencmiss.org
# For more information see http://www.opencmiss.org/documentation

# Include the OpenCMISS initalisation & macro definition file.
include(./OpenCMISS.cmake)

# Project setup
# -------------
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(OpenCMISS-Example VERSION 1.0 LANGUAGES C)
enable_language(Fortran OPTIONAL)
enable_testing()

# Find OpenCMISS
# --------------
#
# This call tries to find a matching OpenCMISS (SDK) installation for your (default) Toolchain and MPI choice.
# Currently available OpenCMISS package components: Iron Zinc
# Requiring Iron will also include the iron_c bindings target if available.
#
# This function creates a link target 'opencmiss' that contains references to the requested OpenCMISS components.
# For Iron, it also adds the necessary MPI information - no further find_package(MPI ..) and setting of extra include
# paths needed!
find_package(OpenCMISS 1.1 REQUIRED COMPONENTS Iron CONFIG)

# CMake application code
# ----------------------
#add_subdirectory(C)
if (CMAKE_Fortran_COMPILER)
add_subdirectory(Fortran)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

# Add example executable
add_executable(100k src/100kExample.f90)

# Turn on Fortran preprocessing (#include directives)
if (MSVC)
set(PROC_OPT "/fpp")
else()
set(PROC_OPT "-cpp")
endif()

# in debug mode, add flag that make Floating point exceptions fatal
set(OPT "")
if (FALSE)
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
set(OPT "-ffpe-trap=invalid,zero,underflow,overflow,denormal") # GCC: make floating point exceptions fatal
endif()
endif()

target_compile_options(100k PRIVATE ${PROC_OPT} ${OPT} "-fbacktrace")

# Link to opencmiss
# -----------------
#
# This simply uses the opencmiss target created by OC_INIT() above.
#
# Alternatively, you can also directly invoke 'find_package(Iron <IRON_VERSION>)' to explicitly
# require that version. But then you have to deal with setting up the correct MPI include directives and library paths.
#
# If required, add any other required link libraries (cellml, petsc ..) here, too.
# For example, if you needed PetSC functionality, issue
#
# find_package(PETSC <PETSC_VERSION> REQUIRED)
# target_link_libraries(${EXAMPLE_BINARY} PRIVATE petsc)
#
# All the OpenCMISS dependencies provide a target you can link against corresponding to the (lowercase) component name.
target_link_libraries(100k PRIVATE opencmiss)

# Add a simple test that runs the executable
add_test(NAME test_100k COMMAND 100k)
add_opencmiss_environment(test_100k)

###################
# Developer notice!
#
# If you write Fortran code and use MPI, you need to use the following MPI directives:
#
# #ifndef NOMPIMOD
# USE MPI
# #endif
# [...]
# IMPLICIT NONE
# [...]
# #ifdef NOMPIMOD
# #include "mpif.h"
# #endif
#
# Reasoning: In some cases like Windows/MPICH2 there sometimes is no mpi.mod file. In order to yet make
# the example work the build system adds the definition 'NOMPIMOD', which can be checked and acted to accordingly.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
###########################
# *DO NOT CHANGE THIS FILE*
###########################
#
# Prepares the use of OpenCMISS by scanning at various path locations for OpenCMISS (SDK) installations.
#
# Search order:
# - OPENCMISS_INSTALL_DIR variable
# - OPENCMISS_INSTALL_DIR environment variable
# - OPENCMISS_SDK_DIR variable
# - OPENCMISS_SDK_DIR environment variable
# - [Windows only] The Registry is searched additionally for installed SDKs.
#
# If found
# - Includes the toolchain config script of the found opencmiss installation to enable toolchain selection logic (non-windows)

# Convenience: The OPENCMISS_INSTALL_DIR may also be defined in the environment and various other places
if (DEFINED OPENCMISS_INSTALL_DIR)
get_filename_component(OPENCMISS_INSTALL_DIR "${OPENCMISS_INSTALL_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
message(STATUS "Using specified installation directory '${OPENCMISS_INSTALL_DIR}'")
else()
message(WARNING "The specified OPENCMISS_INSTALL_DIR '${OPENCMISS_INSTALL_DIR}' does not exist. Skipping.")
unset(OPENCMISS_INSTALL_DIR)
endif()
endif()
if(NOT OPENCMISS_INSTALL_DIR AND NOT "$ENV{OPENCMISS_INSTALL_DIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{OPENCMISS_INSTALL_DIR}" OPENCMISS_INSTALL_DIR)
get_filename_component(OPENCMISS_INSTALL_DIR "${OPENCMISS_INSTALL_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
message(STATUS "Using environment installation directory '${OPENCMISS_INSTALL_DIR}'")
else()
message(WARNING "The environment variable OPENCMISS_INSTALL_DIR='${OPENCMISS_INSTALL_DIR}' contains an invalid path. Skipping.")
unset(OPENCMISS_INSTALL_DIR)
endif()
endif()
if (NOT OPENCMISS_INSTALL_DIR AND DEFINED OPENCMISS_SDK_DIR)
get_filename_component(OPENCMISS_SDK_DIR "${OPENCMISS_SDK_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_SDK_DIR}")
message(STATUS "Using SDK installation directory: ${OPENCMISS_SDK_DIR}")
set(OPENCMISS_INSTALL_DIR "${OPENCMISS_SDK_DIR}")
else()
message(WARNING "The specified OPENCMISS_SDK_DIR '${OPENCMISS_SDK_DIR}' does not exist. Skipping.")
endif()
endif()
if(NOT OPENCMISS_INSTALL_DIR AND NOT "$ENV{OPENCMISS_SDK_DIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{OPENCMISS_SDK_DIR}" OPENCMISS_SDK_DIR)
get_filename_component(OPENCMISS_SDK_DIR "${OPENCMISS_SDK_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_SDK_DIR}")
message(STATUS "Using environment SDK installation directory: ${OPENCMISS_SDK_DIR}")
set(OPENCMISS_INSTALL_DIR "${OPENCMISS_SDK_DIR}")
else()
message(WARNING "The environment variable OPENCMISS_SDK_DIR='${OPENCMISS_SDK_DIR}' contains an invalid path. Skipping.")
unset(OPENCMISS_SDK_DIR)
endif()
endif()
# On windows: check the registry for installed OpenCMISS SDKs
if(NOT OPENCMISS_INSTALL_DIR AND WIN32)
foreach(ROOT HKEY_CURRENT_USER HKEY_LOCAL_MACHINE)
foreach(PACKAGE OpenCMISSUserSDK OpenCMISSDeveloperSDK)
set(_REG_KEY "[${ROOT}\\Software\\Auckland Bioengineering Institute\\${PACKAGE}]")
get_filename_component(OPENCMISS_INSTALL_DIR "${_REG_KEY}" ABSOLUTE)
#message(STATUS "Trying registry key ${_REG_KEY}: ${OPENCMISS_INSTALL_DIR}")
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
message(STATUS "Found ${PACKAGE} in Windows registry key ${_REG_KEY}: ${OPENCMISS_INSTALL_DIR}")
break()
else()
unset(OPENCMISS_INSTALL_DIR)
endif()
endforeach()
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
break()
endif()
endforeach()
endif()

if(OPENCMISS_INSTALL_DIR)
message(STATUS "OPENCMISS_INSTALL_DIR=${OPENCMISS_INSTALL_DIR}")
# Use the OpenCMISS scripts to also allow choosing a separate toolchain
# This file is located at the opencmiss installation rather than the local example
# as it avoids file replication and makes maintenance much easier
if (TOOLCHAIN)
set(_OCTC ${OPENCMISS_INSTALL_DIR}/cmake/OCToolchainCompilers.cmake)
if (EXISTS "${_OCTC}")
include(${_OCTC})
else()
message(WARNING "TOOLCHAIN specified but OpenCMISS config script could not be found at ${_OCTC}. Trying CMake defaults.")
endif()
unset(_OCTC)
endif()
set(OpenCMISS_DIR "${OPENCMISS_INSTALL_DIR}" CACHE PATH "Path to the found OpenCMISS (SDK) installation")
else()
message(WARNING "No OpenCMISS (SDK) installation directory detected. Using default system environment.")
endif()

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#ccc && cmake -DOPENCMISS_BUILD_TYPE=DEBUG -DCMAKE_BUILD_TYPE=DEBUG .. && make all
cmake -DOPENCMISS_BUILD_TYPE=DEBUG -DCMAKE_BUILD_TYPE=DEBUG .. && make all
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# OpenCMISS (Open Continuum Mechanics, Imaging, Signal processing and System identification)
# is a mathematical modelling environment that enables the application of finite element
# analysis techniques to a variety of complex bioengineering problems.
#
# The OpenCMISS project website can be found at http://www.opencmiss.org
# For more information see http://www.opencmiss.org/documentation

# Include the OpenCMISS initalisation & macro definition file.
include(./OpenCMISS.cmake)

# Project setup
# -------------
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(OpenCMISS-Example VERSION 1.0 LANGUAGES C)
enable_language(Fortran OPTIONAL)
enable_testing()

# Find OpenCMISS
# --------------
#
# This call tries to find a matching OpenCMISS (SDK) installation for your (default) Toolchain and MPI choice.
# Currently available OpenCMISS package components: Iron Zinc
# Requiring Iron will also include the iron_c bindings target if available.
#
# This function creates a link target 'opencmiss' that contains references to the requested OpenCMISS components.
# For Iron, it also adds the necessary MPI information - no further find_package(MPI ..) and setting of extra include
# paths needed!
find_package(OpenCMISS 1.1 REQUIRED COMPONENTS Iron CONFIG)

# CMake application code
# ----------------------
#add_subdirectory(C)
if (CMAKE_Fortran_COMPILER)
add_subdirectory(Fortran)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

# Add example executable
add_executable(10k src/10kExample.f90)

# Turn on Fortran preprocessing (#include directives)
if (MSVC)
set(PROC_OPT "/fpp")
else()
set(PROC_OPT "-cpp")
endif()

# in debug mode, add flag that make Floating point exceptions fatal
set(OPT "")
if (FALSE)
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
set(OPT "-ffpe-trap=invalid,zero,underflow,overflow,denormal") # GCC: make floating point exceptions fatal
endif()
endif()

target_compile_options(10k PRIVATE ${PROC_OPT} ${OPT} "-fbacktrace")

# Link to opencmiss
# -----------------
#
# This simply uses the opencmiss target created by OC_INIT() above.
#
# Alternatively, you can also directly invoke 'find_package(Iron <IRON_VERSION>)' to explicitly
# require that version. But then you have to deal with setting up the correct MPI include directives and library paths.
#
# If required, add any other required link libraries (cellml, petsc ..) here, too.
# For example, if you needed PetSC functionality, issue
#
# find_package(PETSC <PETSC_VERSION> REQUIRED)
# target_link_libraries(${EXAMPLE_BINARY} PRIVATE petsc)
#
# All the OpenCMISS dependencies provide a target you can link against corresponding to the (lowercase) component name.
target_link_libraries(10k PRIVATE opencmiss)

# Add a simple test that runs the executable
add_test(NAME test_10k COMMAND 10k)
add_opencmiss_environment(test_10k)

###################
# Developer notice!
#
# If you write Fortran code and use MPI, you need to use the following MPI directives:
#
# #ifndef NOMPIMOD
# USE MPI
# #endif
# [...]
# IMPLICIT NONE
# [...]
# #ifdef NOMPIMOD
# #include "mpif.h"
# #endif
#
# Reasoning: In some cases like Windows/MPICH2 there sometimes is no mpi.mod file. In order to yet make
# the example work the build system adds the definition 'NOMPIMOD', which can be checked and acted to accordingly.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
###########################
# *DO NOT CHANGE THIS FILE*
###########################
#
# Prepares the use of OpenCMISS by scanning at various path locations for OpenCMISS (SDK) installations.
#
# Search order:
# - OPENCMISS_INSTALL_DIR variable
# - OPENCMISS_INSTALL_DIR environment variable
# - OPENCMISS_SDK_DIR variable
# - OPENCMISS_SDK_DIR environment variable
# - [Windows only] The Registry is searched additionally for installed SDKs.
#
# If found
# - Includes the toolchain config script of the found opencmiss installation to enable toolchain selection logic (non-windows)

# Convenience: The OPENCMISS_INSTALL_DIR may also be defined in the environment and various other places
if (DEFINED OPENCMISS_INSTALL_DIR)
get_filename_component(OPENCMISS_INSTALL_DIR "${OPENCMISS_INSTALL_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
message(STATUS "Using specified installation directory '${OPENCMISS_INSTALL_DIR}'")
else()
message(WARNING "The specified OPENCMISS_INSTALL_DIR '${OPENCMISS_INSTALL_DIR}' does not exist. Skipping.")
unset(OPENCMISS_INSTALL_DIR)
endif()
endif()
if(NOT OPENCMISS_INSTALL_DIR AND NOT "$ENV{OPENCMISS_INSTALL_DIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{OPENCMISS_INSTALL_DIR}" OPENCMISS_INSTALL_DIR)
get_filename_component(OPENCMISS_INSTALL_DIR "${OPENCMISS_INSTALL_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
message(STATUS "Using environment installation directory '${OPENCMISS_INSTALL_DIR}'")
else()
message(WARNING "The environment variable OPENCMISS_INSTALL_DIR='${OPENCMISS_INSTALL_DIR}' contains an invalid path. Skipping.")
unset(OPENCMISS_INSTALL_DIR)
endif()
endif()
if (NOT OPENCMISS_INSTALL_DIR AND DEFINED OPENCMISS_SDK_DIR)
get_filename_component(OPENCMISS_SDK_DIR "${OPENCMISS_SDK_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_SDK_DIR}")
message(STATUS "Using SDK installation directory: ${OPENCMISS_SDK_DIR}")
set(OPENCMISS_INSTALL_DIR "${OPENCMISS_SDK_DIR}")
else()
message(WARNING "The specified OPENCMISS_SDK_DIR '${OPENCMISS_SDK_DIR}' does not exist. Skipping.")
endif()
endif()
if(NOT OPENCMISS_INSTALL_DIR AND NOT "$ENV{OPENCMISS_SDK_DIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{OPENCMISS_SDK_DIR}" OPENCMISS_SDK_DIR)
get_filename_component(OPENCMISS_SDK_DIR "${OPENCMISS_SDK_DIR}" ABSOLUTE)
if (EXISTS "${OPENCMISS_SDK_DIR}")
message(STATUS "Using environment SDK installation directory: ${OPENCMISS_SDK_DIR}")
set(OPENCMISS_INSTALL_DIR "${OPENCMISS_SDK_DIR}")
else()
message(WARNING "The environment variable OPENCMISS_SDK_DIR='${OPENCMISS_SDK_DIR}' contains an invalid path. Skipping.")
unset(OPENCMISS_SDK_DIR)
endif()
endif()
# On windows: check the registry for installed OpenCMISS SDKs
if(NOT OPENCMISS_INSTALL_DIR AND WIN32)
foreach(ROOT HKEY_CURRENT_USER HKEY_LOCAL_MACHINE)
foreach(PACKAGE OpenCMISSUserSDK OpenCMISSDeveloperSDK)
set(_REG_KEY "[${ROOT}\\Software\\Auckland Bioengineering Institute\\${PACKAGE}]")
get_filename_component(OPENCMISS_INSTALL_DIR "${_REG_KEY}" ABSOLUTE)
#message(STATUS "Trying registry key ${_REG_KEY}: ${OPENCMISS_INSTALL_DIR}")
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
message(STATUS "Found ${PACKAGE} in Windows registry key ${_REG_KEY}: ${OPENCMISS_INSTALL_DIR}")
break()
else()
unset(OPENCMISS_INSTALL_DIR)
endif()
endforeach()
if (EXISTS "${OPENCMISS_INSTALL_DIR}")
break()
endif()
endforeach()
endif()

if(OPENCMISS_INSTALL_DIR)
message(STATUS "OPENCMISS_INSTALL_DIR=${OPENCMISS_INSTALL_DIR}")
# Use the OpenCMISS scripts to also allow choosing a separate toolchain
# This file is located at the opencmiss installation rather than the local example
# as it avoids file replication and makes maintenance much easier
if (TOOLCHAIN)
set(_OCTC ${OPENCMISS_INSTALL_DIR}/cmake/OCToolchainCompilers.cmake)
if (EXISTS "${_OCTC}")
include(${_OCTC})
else()
message(WARNING "TOOLCHAIN specified but OpenCMISS config script could not be found at ${_OCTC}. Trying CMake defaults.")
endif()
unset(_OCTC)
endif()
set(OpenCMISS_DIR "${OPENCMISS_INSTALL_DIR}" CACHE PATH "Path to the found OpenCMISS (SDK) installation")
else()
message(WARNING "No OpenCMISS (SDK) installation directory detected. Using default system environment.")
endif()

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#ccc && cmake -DOPENCMISS_BUILD_TYPE=DEBUG -DCMAKE_BUILD_TYPE=DEBUG .. && make all
cmake -DOPENCMISS_BUILD_TYPE=DEBUG -DCMAKE_BUILD_TYPE=DEBUG .. && make all
Loading