Skip to content

Commit

Permalink
Allow passing PUBLIC_DEFINITIONS to ecbuild_add_library for INTERFACE…
Browse files Browse the repository at this point in the history
… libraries
  • Loading branch information
wdeconinck committed Jun 10, 2024
1 parent 889ab11 commit 441e967
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 5 deletions.
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
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: 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 441e967

Please sign in to comment.