Skip to content

Instantly share code, notes, and snippets.

@hegish
Created May 17, 2017 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hegish/fd62aacbc9f5199eab71908a30437780 to your computer and use it in GitHub Desktop.
Save hegish/fd62aacbc9f5199eab71908a30437780 to your computer and use it in GitHub Desktop.
simple pfunit unit test build using cmake
cmake_minimum_required(VERSION 3.7)
project(pfunittests.x Fortran)
# create the corresponding F90 file for all our pfunit files (*.pf) via pFUnitParser.py
file(GLOB pfunitparser_files ${CMAKE_CURRENT_LIST_DIR}/*.pf)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_CURRENT_LIST_DIR})
foreach(f ${pfunitparser_files})
set(outfile ${CMAKE_CURRENT_BINARY_DIR}${f}.F90)
add_custom_target(run ALL DEPENDS ${outfile})
add_custom_command(
OUTPUT ${outfile}
COMMAND python $ENV{PFUNIT}/bin/pFUnitParser.py ${f} ${outfile}
DEPENDS ${f}
)
list(APPEND sources_Fortran ${outfile})
endforeach()
list(APPEND sources_Fortran $ENV{PFUNIT}/include/driver.F90)
find_library(PFUNIT_Fortran_LIBRARIES pfunit HINTS $ENV{PFUNIT}/lib)
# here we could choose another directory for the actual sources under test
file(GLOB sources_under_test ${CMAKE_CURRENT_LIST_DIR}/*.F90)
list(APPEND sources_Fortran ${sources_under_test})
add_executable(${PROJECT_NAME} ${sources_Fortran})
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel )
target_compile_options(${PROJECT_NAME} PRIVATE -r8 -i4 -fp-model precise)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU )
target_compile_options(${PROJECT_NAME} PRIVATE -fdefault-real-8 -ffree-line-length-none)
endif()
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR} $ENV{PFUNIT}/mod)
target_link_libraries(${PROJECT_NAME} ${PFUNIT_Fortran_LIBRARIES})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment