Created
May 17, 2017 12:37
-
-
Save hegish/fd62aacbc9f5199eab71908a30437780 to your computer and use it in GitHub Desktop.
simple pfunit unit test build using cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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