Skip to content

Commit

Permalink
Merge branch 'hotfix/3.8.4'
Browse files Browse the repository at this point in the history
* hotfix/3.8.4:
  Version 3.8.4
  Project specific and target specific library type override (#60)
  • Loading branch information
wdeconinck committed Apr 22, 2024
2 parents 975f59e + e7e866a commit 889ab11
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmake/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.3
3.8.4
6 changes: 6 additions & 0 deletions cmake/ecbuild_add_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ function( ecbuild_add_library_impl )
ecbuild_critical("The call to ecbuild_add_library() doesn't specify the TARGET.")
endif()

### optional override for target type
if( NOT DEFINED _PAR_TYPE AND DEFINED ECBUILD_TARGET_${_PAR_TARGET}_TYPE )
set( _PAR_TYPE ${ECBUILD_TARGET_${_PAR_TARGET}_TYPE} )
ecbuild_debug( "ecbuild_add_libary(${_PAR_TARGET}): library type overriden to ${_PAR_TYPE}" )
endif()

if( NOT _PAR_TYPE MATCHES "INTERFACE" )
if( NOT _PAR_SOURCES AND NOT _PAR_OBJECTS AND NOT _PAR_SOURCES_GLOB )
ecbuild_critical("The call to ecbuild_add_library() specifies neither SOURCES nor OBJECTS nor SOURCES_GLOB")
Expand Down
9 changes: 9 additions & 0 deletions cmake/ecbuild_project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ macro( project _project_name )

ecbuild_declare_project()

### override BUILD_SHARED_LIBS property
if( DEFINED ${PNAME}_BUILD_SHARED_LIBS )
if( NOT ${${PNAME}_BUILD_SHARED_LIBS} MATCHES "ON|OFF" )
ecbuild_critical( "${${PNAME}_BUILD_SHARED_LIBS} must be one of [ON|OFF]" )
endif()
set( BUILD_SHARED_LIBS ${${PNAME}_BUILD_SHARED_LIBS} )
ecbuild_debug( "ecbuild_project(${_project_name}): static libraries set as default for project" )
endif()

else() # ecbuild 2 or pure CMake

ecbuild_debug( "CMake project(${_project_name}) ")
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ add_subdirectory( ecbuild_add_option )
add_subdirectory( ecbuild_add_flags )
add_subdirectory( find_ecbuild )
add_subdirectory( project_import )
add_subdirectory( ecbuild_shared_libs )
7 changes: 7 additions & 0 deletions tests/ecbuild_shared_libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

ecbuild_add_test(
TARGET test_ecbuild_shared_libs
TYPE SCRIPT
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build-and-run.sh
ENVIRONMENT CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
)
72 changes: 72 additions & 0 deletions tests/ecbuild_shared_libs/build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

set -e

HERE=${CMAKE_CURRENT_BINARY_DIR:-"$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd -P )"}
SOURCE=${CMAKE_CURRENT_SOURCE_DIR:-$HERE}

# Add ecbuild to path
export PATH=$SOURCE/../../bin:$PATH
echo $PATH
echo $SOURCE

check_lib_exists() {

local libname=$1
local ext=$2

if [ ! -f $HERE/build/lib/lib${libname}.$ext ]; then
echo "$HERE/build/lib/lib${libname}.$ext not found"
exit 1
fi

}

dyn_ext="so"
if [[ $(uname) == "Darwin" ]]; then
dyn_ext="dylib"
fi
static_ext="a"

logf=$HERE/test_ecbuild_shared_libs.log

# enable shared libraries across project
$SOURCE/clean.sh
ecbuild -DENABLE_TESTS=OFF -DTEST_SHARED_LIBS_BUILD_SHARED_LIBS=OFF $SOURCE/test_project -B $HERE/build
cmake --build build
check_lib_exists test_shared_libs ${static_ext}
check_lib_exists lib2 ${static_ext}
check_lib_exists lib1 ${dyn_ext}

# test that BUILD_SHARED_LIBS is overriden
$SOURCE/clean.sh
ecbuild -DENABLE_TESTS=OFF -DTEST_SHARED_LIBS_BUILD_SHARED_LIBS=OFF -DBUILD_SHARED_LIBS=ON $SOURCE/test_project -B $HERE/build
cmake --build build
check_lib_exists test_shared_libs ${static_ext}
check_lib_exists lib2 ${static_ext}
check_lib_exists lib1 ${dyn_ext}

# test ecbuild failure for invalid argument
$SOURCE/clean.sh
ecbuild -DENABLE_TESTS=OFF -DTEST_SHARED_LIBS_BUILD_SHARED_LIBS=SHARED $SOURCE/test_project -B $HERE/build >$logf 2>&1 || result=$?
if [ ! $result ]; then
echo "ecbuild should have failed for invalid argument"
cat $logf
exit 1
fi

# enable target specific override 1
$SOURCE/clean.sh
ecbuild -DENABLE_TESTS=OFF -DECBUILD_TARGET_test_shared_libs_TYPE=SHARED -DBUILD_SHARED_LIBS=OFF $SOURCE/test_project -B $HERE/build
cmake --build build
check_lib_exists test_shared_libs ${dyn_ext}
check_lib_exists lib2 ${static_ext}
check_lib_exists lib1 ${dyn_ext}

# enable target specific override 2
$SOURCE/clean.sh
ecbuild -DENABLE_TESTS=OFF -DECBUILD_TARGET_test_shared_libs_TYPE=STATIC $SOURCE/test_project -B $HERE/build
cmake --build build
check_lib_exists test_shared_libs ${static_ext}
check_lib_exists lib2 ${dyn_ext}
check_lib_exists lib1 ${dyn_ext}
10 changes: 10 additions & 0 deletions tests/ecbuild_shared_libs/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

HERE=${CMAKE_CURRENT_BINARY_DIR:-"$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd -P )"}

# --------------------- cleanup ------------------------
echo "cleaning $HERE"
rm -rf $HERE/build
rm -f $HERE/*.log
11 changes: 11 additions & 0 deletions tests/ecbuild_shared_libs/test_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)

find_package( ecbuild REQUIRED )
project( test_shared_libs VERSION 0.1.0 LANGUAGES Fortran )

ecbuild_add_library( TARGET test_shared_libs SOURCES dummy_src.F90 )

# this should never be overriden
ecbuild_add_library( TARGET lib1 TYPE SHARED SOURCES dummy_src.F90 )

ecbuild_add_library( TARGET lib2 SOURCES dummy_src.F90 )
3 changes: 3 additions & 0 deletions tests/ecbuild_shared_libs/test_project/dummy_src.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
program main

end program

0 comments on commit 889ab11

Please sign in to comment.