-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ecbuild_override_compiler_flags macro
- Loading branch information
Showing
9 changed files
with
187 additions
and
64 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set(_dir ${CMAKE_CURRENT_BINARY_DIR}) | ||
configure_file(run-test.sh.in ${_dir}/run-test.sh @ONLY) | ||
configure_file(test_ecbuild_override_compiler_flags.cmake ${_dir}/CMakeLists.txt COPYONLY) | ||
configure_file(emptyfile.c ${_dir}/emptyfile.c COPYONLY) | ||
configure_file(emptyfile.cxx ${_dir}/emptyfile.cxx COPYONLY) | ||
configure_file(emptyfile.F90 ${_dir}/emptyfile.F90 COPYONLY) | ||
configure_file(compiler_flags.cmake ${_dir}/compiler_flags.cmake COPYONLY) | ||
|
||
ecbuild_add_test( | ||
TARGET test_ecbuild_override_compiler_flags | ||
TYPE SCRIPT | ||
COMMAND run-test.sh | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
set( OVERRIDECOMPILERFLAGS_C_FLAGS "-g -fPIC" ) | ||
set( OVERRIDECOMPILERFLAGS_CXX_FLAGS "-g -fPIC" ) | ||
set( OVERRIDECOMPILERFLAGS_Fortran_FLAGS "-g -fortran_only_flag" ) | ||
|
||
set( OVERRIDECOMPILERFLAGS_C_FLAGS_DEBUG "-O0" ) | ||
set( OVERRIDECOMPILERFLAGS_CXX_FLAGS_DEBUG "-O0" ) | ||
|
||
set( OVERRIDECOMPILERFLAGS_C_FLAGS_BIT "-O2" ) | ||
set( OVERRIDECOMPILERFLAGS_CXX_FLAGS_BIT "-O2" ) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
! An empty file |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// An empty file |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// An empty file |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
HERE="$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd -P )" | ||
|
||
cd $HERE | ||
|
||
rm -rf build # cleanup | ||
mkdir build | ||
cd build | ||
|
||
cmake -DCMAKE_MODULE_PATH=@ECBUILD_MACROS_DIR@ -DECBUILD_LOG_LEVEL=DEBUG -DCMAKE_BUILD_TYPE=BIT -DECBUILD_SOURCE_FLAGS=@CMAKE_CURRENT_SOURCE_DIR@/flags-sourceflags.json .. | ||
|
||
cd .. | ||
|
||
rm -rf build # cleanup | ||
mkdir build | ||
cd build | ||
|
||
cmake -DCMAKE_MODULE_PATH=@ECBUILD_MACROS_DIR@ -DECBUILD_LOG_LEVEL=DEBUG -DCMAKE_BUILD_TYPE=DEBUG -DECBUILD_SOURCE_FLAGS=@CMAKE_CURRENT_SOURCE_DIR@/flags-sourceflags.json .. | ||
|
45 changes: 45 additions & 0 deletions
45
tests/ecbuild_override_compiler_flags/test_ecbuild_override_compiler_flags.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
cmake_minimum_required( VERSION 3.12 FATAL_ERROR ) | ||
|
||
find_package( ecbuild 3.6 REQUIRED ) | ||
|
||
project(OverrideCompilerFlags VERSION 1.0 LANGUAGES C CXX Fortran) | ||
|
||
ecbuild_override_compiler_flags( COMPILE_FLAGS compiler_flags.cmake ) | ||
|
||
ecbuild_add_library( | ||
TARGET overrideflags | ||
SOURCES emptyfile.c emptyfile.cxx emptyfile.F90 | ||
) | ||
|
||
get_property( _flags SOURCE emptyfile.c PROPERTY COMPILE_FLAGS ) | ||
if( CMAKE_BUILD_TYPE MATCHES BIT ) | ||
if( NOT ${_flags} MATCHES "-g -fPIC -O2" ) | ||
message(${_flags}) | ||
message(FATAL_ERROR "Incorrect BIT flags for emptyfile.c") | ||
endif() | ||
elseif( CMAKE_BUILD_TYPE MATCHES DEBUG ) | ||
if( NOT ${_flags} MATCHES "-g -fPIC -O0" ) | ||
message(${_flags}) | ||
message(FATAL_ERROR "Incorrect DEBUG flags for emptyfile.c") | ||
endif() | ||
endif() | ||
|
||
get_property( _flags SOURCE emptyfile.cxx PROPERTY COMPILE_FLAGS ) | ||
if( CMAKE_BUILD_TYPE MATCHES BIT ) | ||
if( NOT ${_flags} MATCHES "-g -fPIC -O2" ) | ||
message(${_flags}) | ||
message(FATAL_ERROR "Incorrect BIT flags for emptyfile.cxx") | ||
endif() | ||
elseif( CMAKE_BUILD_TYPE MATCHES DEBUG ) | ||
if( NOT ${_flags} MATCHES "-g -fPIC -O0" ) | ||
message(${_flags}) | ||
message(FATAL_ERROR "Incorrect DEBUG flags for emptyfile.cxx") | ||
endif() | ||
endif() | ||
|
||
get_property( _flags SOURCE emptyfile.F90 PROPERTY COMPILE_FLAGS ) | ||
if( NOT ${_flags} MATCHES "-g -fortran_only_flag" ) | ||
message(${_flags}) | ||
message(FATAL_ERROR "Incorrect flags for emptyfile.F90") | ||
endif() | ||
|