Skip to content

Commit

Permalink
Merge pull request njoy#25 in SCL/cmake from feature/fortran_options …
Browse files Browse the repository at this point in the history
…to master

* commit '4940f27875983f4cf2973707134f5138b46312a2': (21 commits)
  Fixed error when removing dead code
  Remove dead code in IntelWarn.cmake
  Modified IntelDiagDisable and IntelWarn
  deleted orphaned file
  Testing updated to work with WIN32
  Explicit testing for compliers with 'NULL' result
  Alternative impl for TempArrayHeapAlloc
  updated testing directory
  Generalized Fortran Standard work and updated tests
  Fixed broken previous commit
  moved files
  Modified TempArrayHeapAlloc to use target property
  Removed unused TempArrayHeapAlloc files
  Created highest level testing CMakeLists.txt
  Added test to TempArrayHeapAlloc.cmake to prevent generating same target
  Update Intel-specific tests for other compilers
  Add tests for Backtrace, Standard2008, & FreeForm
  Added IntelDiagDisable and IntelWarn tests
  Added Fortran_IntelWarn interface
  Added target to disable Intel diagnostics
  ...
  • Loading branch information
clellsolomon committed Mar 28, 2018
2 parents fcfc1cd + 4940f27 commit 627c7bc
Show file tree
Hide file tree
Showing 63 changed files with 460 additions and 0 deletions.
10 changes: 10 additions & 0 deletions FortranCompileOptions/Backtrace.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include(Backports/IncludeGuard)
include_guard(GLOBAL)

add_library(Fortran_Backtrace INTERFACE)
add_library(FortranCompileOptions::Backtrace ALIAS Fortran_Backtrace)

include(FortranCompileOptions/Backtrace/Intel)
include(FortranCompileOptions/Backtrace/PGI)
# traceback with GNU is default
# traceback with Flang is default
7 changes: 7 additions & 0 deletions FortranCompileOptions/Backtrace/Intel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
string(CONCAT generator
"$<$<STREQUAL:Intel,${CMAKE_Fortran_COMPILER_ID}>:"
"$<$<NOT:$<PLATFORM_ID:Windows>>:-traceback>"
"$<$<PLATFORM_ID:Windows>:/traceback>>"
)

target_compile_options(Fortran_Backtrace INTERFACE ${generator})
5 changes: 5 additions & 0 deletions FortranCompileOptions/Backtrace/PGI.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
string(CONCAT generator
"$<$<STREQUAL:PGI,${CMAKE_Fortran_COMPILER_ID}>:-traceback>"
)

target_compile_options(Fortran_Backtrace INTERFACE ${generator})
10 changes: 10 additions & 0 deletions FortranCompileOptions/FreeForm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include(Backports/IncludeGuard)
include_guard(GLOBAL)

add_library(Fortran_FreeForm INTERFACE)
add_library(FortranCompileOptions::FreeForm ALIAS Fortran_FreeForm)

include(FortranCompileOptions/FreeForm/Intel)
include(FortranCompileOptions/FreeForm/GNU)
include(FortranCompileOptions/FreeForm/Flang)
include(FortranCompileOptions/FreeForm/PGI)
5 changes: 5 additions & 0 deletions FortranCompileOptions/FreeForm/Flang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
string(CONCAT generator
"$<$<STREQUAL:Flang,${CMAKE_Fortran_COMPILER_ID}>:-ffree-form>"
)

target_compile_options(Fortran_FreeForm INTERFACE ${generator})
5 changes: 5 additions & 0 deletions FortranCompileOptions/FreeForm/GNU.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
string(CONCAT generator
"$<$<STREQUAL:GNU,${CMAKE_Fortran_COMPILER_ID}>:-ffree-form>"
)

target_compile_options(Fortran_FreeForm INTERFACE ${generator})
7 changes: 7 additions & 0 deletions FortranCompileOptions/FreeForm/Intel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
string(CONCAT generator
"$<$<STREQUAL:Intel,${CMAKE_Fortran_COMPILER_ID}>:"
"$<$<NOT:$<PLATFORM_ID:Windows>>:-free>"
"$<$<PLATFORM_ID:Windows>:/free>>"
)

target_compile_options(Fortran_FreeForm INTERFACE ${generator})
5 changes: 5 additions & 0 deletions FortranCompileOptions/FreeForm/PGI.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
string(CONCAT generator
"$<$<STREQUAL:PGI,${CMAKE_Fortran_COMPILER_ID}>:-Mfree>"
)

target_compile_options(Fortran_FreeForm INTERFACE ${generator})
21 changes: 21 additions & 0 deletions FortranCompileOptions/IntelDiagDisable.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include(Backports/IncludeGuard)
include_guard(GLOBAL)

if( "Intel" STREQUAL "${CMAKE_Fortran_COMPILER_ID}")
set(Fortran.Intel.DiagDisable "" CACHE STRING "semicolon-separated list of Intel Fortran diagnostic numbers to dissable")
mark_as_advanced(Fortran.Intel.DiagDisable)
endif()

add_library(Fortran_IntelDiagDisable INTERFACE)
add_library(FortranCompileOptions::IntelDiagDisable ALIAS Fortran_IntelDiagDisable)

string(CONCAT generator
"$<$<BOOL:$<JOIN:${Fortran.Intel.DiagDisable},>>:"
"$<$<STREQUAL:Intel,${CMAKE_Fortran_COMPILER_ID}>:"
"$<$<NOT:$<PLATFORM_ID:Windows>>:-diag-disable;$<JOIN:${Fortran.Intel.DiagDisable},$<COMMA>>>"
"$<$<PLATFORM_ID:Windows>:/Qdiag-disable:$<JOIN:${Fortran.Intel.DiagDisable},$<COMMA>>>"
">"
">"
)

target_compile_options(Fortran_IntelDiagDisable INTERFACE ${generator})
21 changes: 21 additions & 0 deletions FortranCompileOptions/IntelWarn.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include(Backports/IncludeGuard)
include_guard(GLOBAL)

if( "Intel" STREQUAL "${CMAKE_Fortran_COMPILER_ID}")
set(Fortran.Intel.Warn "" CACHE STRING "semicolon-separated list of Intel Fortran warning keyword")
mark_as_advanced(Fortran.Intel.Warn)
endif()

add_library(Fortran_IntelWarn INTERFACE)
add_library(FortranCompileOptions::IntelWarn ALIAS Fortran_IntelWarn)

string(CONCAT generator
"$<$<BOOL:$<JOIN:${Fortran.Intel.Warn},>>:"
"$<$<STREQUAL:Intel,${CMAKE_Fortran_COMPILER_ID}>:"
"$<$<NOT:$<PLATFORM_ID:Windows>>:-warn;$<JOIN:${Fortran.Intel.Warn},$<COMMA>>>"
"$<$<PLATFORM_ID:Windows>:/warn:$<JOIN:${Fortran.Intel.Warn},$<COMMA>>>"
">"
">"
)

target_compile_options(Fortran_IntelWarn INTERFACE ${generator})
21 changes: 21 additions & 0 deletions FortranCompileOptions/Standard.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include(Backports/IncludeGuard)
include_guard(GLOBAL)

define_property(TARGET PROPERTY Fortran_Standard
BRIEF_DOCS
"The Fortran standard whose features are requested to build this target."
FULL_DOCS
"This property specifies the Fortran standard whose features are requested to
build this target. For some compilers, this results in adding a flag such as
-std=f2003 to the compile line. For compilers that have no notion of a
standard level, such as PGI, this has no effect.
Supported values are 95, 2003, and 2008")

add_library(Fortran_Standard INTERFACE)
add_library(FortranCompileOptions::Standard ALIAS Fortran_Standard)

include(FortranCompileOptions/Standard/Intel)
include(FortranCompileOptions/Standard/GNU)
include(FortranCompileOptions/Standard/PGI)
# TODO: Flang -- it does not implement standards checking yet
9 changes: 9 additions & 0 deletions FortranCompileOptions/Standard/GNU.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
string(CONCAT generator
"$<$<STREQUAL:$<TARGET_PROPERTY:Fortran_Standard>,95>:f95>"
"$<$<STREQUAL:$<TARGET_PROPERTY:Fortran_Standard>,2003>:f2003>"
"$<$<STREQUAL:$<TARGET_PROPERTY:Fortran_Standard>,2008>:f2008>")

string(CONCAT generator
"$<$<STREQUAL:GNU,${CMAKE_Fortran_COMPILER_ID}>:-std=${generator}>")

target_compile_options(Fortran_Standard INTERFACE ${generator})
12 changes: 12 additions & 0 deletions FortranCompileOptions/Standard/Intel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
string(CONCAT generator
"$<$<STREQUAL:$<TARGET_PROPERTY:Fortran_Standard>,95>:f95>"
"$<$<STREQUAL:$<TARGET_PROPERTY:Fortran_Standard>,2003>:f03>"
"$<$<STREQUAL:$<TARGET_PROPERTY:Fortran_Standard>,2008>:f08>")

string(CONCAT generator
"$<$<STREQUAL:Intel,${CMAKE_Fortran_COMPILER_ID}>:"
"$<$<NOT:$<PLATFORM_ID:Windows>>:-stand;${generator}>"
"$<$<PLATFORM_ID:Windows>:/stand:${generator}>>"
)

target_compile_options(Fortran_Standard INTERFACE ${generator})
8 changes: 8 additions & 0 deletions FortranCompileOptions/Standard/PGI.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# PGI cannot check for particular standard, so we check for general standard
# compliance

string(CONCAT generator
"$<$<STREQUAL:PGI,${CMAKE_Fortran_COMPILER_ID}>:-Mstandard>"
)

target_compile_options(Fortran_Standard INTERFACE ${generator})
18 changes: 18 additions & 0 deletions FortranCompileOptions/TempArrayHeapAlloc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include(Backports/IncludeGuard)
include_guard(GLOBAL)

define_property(TARGET PROPERTY Fortran_TempArrayHeapAlloc_THRESHOLD
BRIEF_DOCS
"A threshold (in kilobytes) above which temporary and automatic arrays should be heap allocated"
FULL_DOCS
"A threshold (in kilobytes) above which temporary and automatic arrays should be heap allocated"
)


add_library(Fortran_TempArrayHeapAlloc INTERFACE)
add_library(FortranCompileOptions::TempArrayHeapAlloc ALIAS Fortran_TempArrayHeapAlloc)

include(FortranCompileOptions/TempArrayHeapAlloc/GNU)
include(FortranCompileOptions/TempArrayHeapAlloc/Flang)
include(FortranCompileOptions/TempArrayHeapAlloc/Intel)
include(FortranCompileOptions/TempArrayHeapAlloc/PGI)
9 changes: 9 additions & 0 deletions FortranCompileOptions/TempArrayHeapAlloc/Flang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
string(CONCAT generator
"$<$<STREQUAL:Flang,${CMAKE_Fortran_COMPILER_ID}>"
":$<$<BOOL:$<TARGET_PROPERTY:Fortran_TempArrayHeapAlloc_THRESHOLD>>"
":-fmax-stack-var-size=$<TARGET_PROPERTY:Fortran_TempArrayHeapAlloc_THRESHOLD>000"
">"
">"
)

target_compile_options(Fortran_TempArrayHeapAlloc INTERFACE ${generator})
9 changes: 9 additions & 0 deletions FortranCompileOptions/TempArrayHeapAlloc/GNU.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
string(CONCAT generator
"$<$<STREQUAL:GNU,${CMAKE_Fortran_COMPILER_ID}>"
":$<$<BOOL:$<TARGET_PROPERTY:Fortran_TempArrayHeapAlloc_THRESHOLD>>"
":-fmax-stack-var-size=$<TARGET_PROPERTY:Fortran_TempArrayHeapAlloc_THRESHOLD>000"
">"
">"
)

target_compile_options(Fortran_TempArrayHeapAlloc INTERFACE ${generator})
10 changes: 10 additions & 0 deletions FortranCompileOptions/TempArrayHeapAlloc/Intel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
string(CONCAT generator
"$<$<STREQUAL:Intel,${CMAKE_Fortran_COMPILER_ID}>"
":$<$<BOOL:$<TARGET_PROPERTY:Fortran_TempArrayHeapAlloc_THRESHOLD>>"
":$<$<NOT:$<PLATFORM_ID:Windows>>:-heap-arrays;$<TARGET_PROPERTY:Fortran_TempArrayHeapAlloc_THRESHOLD>>"
"$<$<PLATFORM_ID:Windows>:/heap-arrays:$<TARGET_PROPERTY:Fortran_TempArrayHeapAlloc_THRESHOLD>>"
">"
">"
)

target_compile_options(Fortran_TempArrayHeapAlloc INTERFACE ${generator})
2 changes: 2 additions & 0 deletions FortranCompileOptions/TempArrayHeapAlloc/PGI.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target_compile_options(Fortran_TempArrayHeapAlloc INTERFACE
"$<$<STREQUAL:PGI,${CMAKE_Fortran_COMPILER_ID}>:-Mnostack_arrays>")
1 change: 1 addition & 0 deletions FunctionExtension.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ include(FunctionExtension/set_property)
include(FunctionExtension/set_target_properties)
include(FunctionExtension/target_sources)
include(FunctionExtension/find_package)
include(FunctionExtension/set_target_properties)
9 changes: 9 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.2.0)
project(shacl_cmake LANGUAGES Fortran VERSION 1.0.0)

include(CTest)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/..)

add_subdirectory(FortranCompileOptions)

32 changes: 32 additions & 0 deletions tests/FortranCompileOptions/Backtrace/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
include(FortranCompileOptions/Backtrace)

file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/use_backtrace.f90
INPUT ${CMAKE_CURRENT_LIST_DIR}/use_backtrace.f90.in
)

add_executable(use_backtrace ${CMAKE_CURRENT_BINARY_DIR}/use_backtrace.f90)
target_link_libraries(use_backtrace PRIVATE FortranCompileOptions::Backtrace)

add_custom_target(run_use_backtrace ALL
COMMAND use_backtrace
)
add_dependencies(run_use_backtrace use_backtrace)

if( WIN32 )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
${CMAKE_CURRENT_BINARY_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
NEWLINE_STYLE DOS
)

add_test(NAME run_use_backtrace
COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/terminal_output
${CMAKE_CURRENT_BINARY_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
)
else()
add_test(NAME run_use_backtrace
COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/terminal_output
${CMAKE_CURRENT_SOURCE_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}
)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions tests/FortranCompileOptions/Backtrace/terminal_output_GNU
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-traceback
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/traceback
1 change: 1 addition & 0 deletions tests/FortranCompileOptions/Backtrace/terminal_output_PGI
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-traceback
5 changes: 5 additions & 0 deletions tests/FortranCompileOptions/Backtrace/use_backtrace.f90.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
program use_standard_semantics
open(unit=42,file="terminal_output",status="unknown")
write(42,*) "$<TARGET_PROPERTY:use_backtrace,COMPILE_OPTIONS>"
close(42)
end program
6 changes: 6 additions & 0 deletions tests/FortranCompileOptions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_subdirectory(Backtrace)
add_subdirectory(FreeForm)
add_subdirectory(IntelDiagDisable)
add_subdirectory(IntelWarn)
add_subdirectory(Standard)
add_subdirectory(TempArrayHeapAlloc)
32 changes: 32 additions & 0 deletions tests/FortranCompileOptions/FreeForm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
include(FortranCompileOptions/FreeForm)

file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/use_free_form.f90
INPUT ${CMAKE_CURRENT_LIST_DIR}/use_free_form.f90.in
)

add_executable(use_free_form ${CMAKE_CURRENT_BINARY_DIR}/use_free_form.f90)
target_link_libraries(use_free_form PRIVATE FortranCompileOptions::FreeForm)

add_custom_target(run_use_free_form ALL
COMMAND use_free_form
)
add_dependencies(run_use_free_form use_free_form)

if( WIN32 )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
${CMAKE_CURRENT_BINARY_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
NEWLINE_STYLE DOS
)

add_test(NAME run_use_free_form
COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/terminal_output
${CMAKE_CURRENT_BINARY_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
)
else()
add_test(NAME run_use_free_form
COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/terminal_output
${CMAKE_CURRENT_SOURCE_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}
)
endif()
1 change: 1 addition & 0 deletions tests/FortranCompileOptions/FreeForm/terminal_output_Flang
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-ffree-form
1 change: 1 addition & 0 deletions tests/FortranCompileOptions/FreeForm/terminal_output_GNU
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-ffree-form
1 change: 1 addition & 0 deletions tests/FortranCompileOptions/FreeForm/terminal_output_Intel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-free
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/free
1 change: 1 addition & 0 deletions tests/FortranCompileOptions/FreeForm/terminal_output_PGI
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Mfree
5 changes: 5 additions & 0 deletions tests/FortranCompileOptions/FreeForm/use_free_form.f90.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
program use_standard_semantics
open(unit=42,file="terminal_output",status="unknown")
write(42,*) "$<TARGET_PROPERTY:use_free_form,COMPILE_OPTIONS>"
close(42)
end program
33 changes: 33 additions & 0 deletions tests/FortranCompileOptions/IntelDiagDisable/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(Fortran.Intel.DiagDisable "1138;1138" CACHE STRING "")
include(FortranCompileOptions/IntelDiagDisable)

file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/use_intel_diag_disable.f90
INPUT ${CMAKE_CURRENT_LIST_DIR}/use_intel_diag_disable.f90.in
)

add_executable(use_intel_diag_disable ${CMAKE_CURRENT_BINARY_DIR}/use_intel_diag_disable.f90)
target_link_libraries(use_intel_diag_disable PRIVATE FortranCompileOptions::IntelDiagDisable)

add_custom_target(run_use_intel_diag_disable ALL
COMMAND use_intel_diag_disable
)
add_dependencies(run_use_intel_diag_disable use_intel_diag_disable)

if( WIN32 )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
${CMAKE_CURRENT_BINARY_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
NEWLINE_STYLE DOS
)

add_test(NAME run_use_intel_diag_disable
COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/terminal_output
${CMAKE_CURRENT_BINARY_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}_win32
)
else()
add_test(NAME run_use_intel_diag_disable
COMMAND ${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/terminal_output
${CMAKE_CURRENT_SOURCE_DIR}/terminal_output_${CMAKE_Fortran_COMPILER_ID}
)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-diag-disable;1138,1138
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Qdiag-disable:1138,1138
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
program use_standard_semantics
open(unit=42,file="terminal_output",status="unknown")
write(42,*) "$<TARGET_PROPERTY:use_intel_diag_disable,COMPILE_OPTIONS>"
close(42)
end program
Loading

0 comments on commit 627c7bc

Please sign in to comment.