Skip to content

Commit

Permalink
Merge branch 'hotfix/3.8.5'
Browse files Browse the repository at this point in the history
* hotfix/3.8.5:
  Version 3.8.5
  Add policy to detect invalid indices
  Allow passing PUBLIC_DEFINITIONS to ecbuild_add_library for INTERFACE libraries
  • Loading branch information
wdeconinck committed Jun 20, 2024
2 parents 889ab11 + 15a776d commit a07c0a5
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmake/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.4
3.8.5
14 changes: 9 additions & 5 deletions cmake/ecbuild_add_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,15 @@ function( ecbuild_add_library_impl )
if( "${_p_TYPE}" STREQUAL LIBS )
target_link_libraries( ${_PAR_TARGET} ${_p_INTF} ${deps} )
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): linking with [${deps}] ${_p_INTF}")
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): [${skipped_deps}] not found - not linking ${_p_INTF}")
if( skipped_deps )
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): [${skipped_deps}] not found - not linking ${_p_INTF}")
endif()
else()
target_include_directories( ${_PAR_TARGET} ${_p_INTF} ${deps} )
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): add [${deps}] to include_directories ${_p_INTF}")
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): [${skipped_deps}] not found - not adding to include_directories ${_p_INTF}")
if( skipped_deps )
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): [${skipped_deps}] not found - not adding to include_directories ${_p_INTF}")
endif()
endif()
endfunction()

Expand Down Expand Up @@ -581,16 +585,16 @@ function( ecbuild_add_library_impl )

# add definitions to compilation
if( DEFINED _PAR_PUBLIC_DEFINITIONS )
target_compile_definitions(${_PAR_TARGET} PUBLIC ${_PAR_PUBLIC_DEFINITIONS})
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): adding PUBLIC definitions ${_PAR_PUBLIC_DEFINITIONS}")
target_compile_definitions(${_PAR_TARGET} ${_PUBLIC_INTF} ${_PAR_PUBLIC_DEFINITIONS})
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): adding ${_PUBLIC_INTF} definitions ${_PAR_PUBLIC_DEFINITIONS}")
endif()
if( DEFINED _PAR_PRIVATE_DEFINITIONS )
target_compile_definitions(${_PAR_TARGET} PRIVATE ${_PAR_PRIVATE_DEFINITIONS})
ecbuild_debug("ecbuild_add_library(${_PAR_TARGET}): adding PRIVATE definitions ${_PAR_PRIVATE_DEFINITIONS}")
endif()
if( DEFINED _PAR_DEFINITIONS )
if( _PAR_TYPE MATCHES "INTERFACE" )
target_compile_definitions(${_PAR_TARGET} PUBLIC ${_PAR_DEFINITIONS})
target_compile_definitions(${_PAR_TARGET} INTERFACE ${_PAR_DEFINITIONS})
else()
target_compile_definitions(${_PAR_TARGET} PRIVATE ${_PAR_DEFINITIONS})
endif()
Expand Down
5 changes: 5 additions & 0 deletions cmake/ecbuild_policies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ if( POLICY CMP0074 )
cmake_policy( SET CMP0074 NEW )
endif()

# Detect invalid indices in the ``list()`` command, new in version 3.21
if( POLICY CMP0121 )
cmake_policy( SET CMP0121 NEW )
endif()

endif()
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ add_subdirectory( ecbuild_add_flags )
add_subdirectory( find_ecbuild )
add_subdirectory( project_import )
add_subdirectory( ecbuild_shared_libs )
add_subdirectory( interface_library )
2 changes: 0 additions & 2 deletions tests/ecbuild_add_option/test_project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
find_package( ecbuild REQUIRED )
project( test_add_option VERSION 0.1.0 LANGUAGES NONE )

list(INSERT 0 CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

ecbuild_add_option(FEATURE TEST_A) # should default to ON
ecbuild_add_option(FEATURE TEST_B DEFAULT ON)
ecbuild_add_option(FEATURE TEST_C DEFAULT OFF)
Expand Down
2 changes: 2 additions & 0 deletions tests/interface_library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build_test_interface_library
install_test_interface_library
7 changes: 7 additions & 0 deletions tests/interface_library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

ecbuild_add_test(
TARGET test_ecbuild_interface_library
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}
)
41 changes: 41 additions & 0 deletions tests/interface_library/build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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

run_test() {

local tname=$1
local exp_sts=$2
shift 2

local bdir=$HERE/build_$tname
local idir=$HERE/install_$tname
local logf=$HERE/$tname.log

mkdir -p $bdir && cd $bdir
local sts=0
echo "Running test '$tname'"
ecbuild --prefix=$idir -- -Wno-deprecated $* $SOURCE/test_project >$logf 2>&1 || sts=$?

make install

if [[ $sts -ne $exp_sts ]] ; then
echo "Test '$tname': expected exit code $exp_sts, got $sts"
cat $logf
exit 1
fi
}

# --------------------- cleanup ------------------------
$SOURCE/clean.sh

# ---------------------- tests -------------------------
run_test test_interface_library 0
9 changes: 9 additions & 0 deletions tests/interface_library/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/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_* $HERE/*.log
13 changes: 13 additions & 0 deletions tests/interface_library/test_project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)

find_package( ecbuild REQUIRED )
project( test_interface_library VERSION 0.1.0 LANGUAGES C )

ecbuild_add_library( TARGET intfb_lib TYPE INTERFACE
PUBLIC_INCLUDES
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$ENV{HOME}
PUBLIC_LIBS some_lib
PUBLIC_DEFINITIONS MYDEF=1
)
ecbuild_install_project( NAME test_interface_library )

0 comments on commit a07c0a5

Please sign in to comment.