Skip to content

Commit

Permalink
Changed project-wide shared libs override name and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awnawab committed Apr 18, 2024
1 parent 3fa0ee2 commit 70880bb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cmake/ecbuild_project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ macro( project _project_name )
ecbuild_declare_project()

### override BUILD_SHARED_LIBS property
if( DEFINED ${PNAME}_SHARED_LIBS )
set( BUILD_SHARED_LIBS ${${PNAME}_SHARED_LIBS} )
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()

Expand Down
21 changes: 20 additions & 1 deletion tests/ecbuild_shared_libs/build-and-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,33 @@ if [[ $(uname) == "Darwin" ]]; then
fi
static_ext="a"

logf=$HERE/test_ecbuild_shared_libs.log

# enable shared libraries across project
$SOURCE/clean.sh
ecbuild -DENABLE_TESTS=OFF -DBUILD_SHARED_LIBS=OFF $SOURCE/test_project -B $HERE/build
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
Expand Down
1 change: 1 addition & 0 deletions tests/ecbuild_shared_libs/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ HERE=${CMAKE_CURRENT_BINARY_DIR:-"$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd
# --------------------- cleanup ------------------------
echo "cleaning $HERE"
rm -rf $HERE/build
rm -f $HERE/*.log

0 comments on commit 70880bb

Please sign in to comment.