diff --git a/src/cmake/modules/CUnit.cmake b/src/cmake/modules/CUnit.cmake index a0021b9..6fa9a1a 100644 --- a/src/cmake/modules/CUnit.cmake +++ b/src/cmake/modules/CUnit.cmake @@ -16,6 +16,14 @@ include(Glob) set(CUNIT_DIR "${CMAKE_CURRENT_LIST_DIR}/CUnit") function(add_cunit_executable target) + # Retrieve location of shared libary, which is need to extend the PATH + # environment variable on Microsoft Windows, so that the operating + # system can locate the .dll that it was linked against. + # On macOS, this mechanism is used to set the DYLD_LIBRARY_PATH. + get_target_property(CUNIT_LIBRARY_TYPE CUnit TYPE) + get_target_property(CUNIT_IMPORTED_LOCATION CUnit IMPORTED_LOCATION) + get_filename_component(CUNIT_LIBRARY_DIR "${CUNIT_IMPORTED_LOCATION}" PATH) + # Generate semi-random filename to store the generated code in to avoid # possible naming conflicts. string(RANDOM random) @@ -114,6 +122,16 @@ function(add_cunit_executable target) add_test( NAME "CUnit_${suite}_${test}" COMMAND ${target} -a -r "${suite}-${test}" -s ${suite} -t ${test}) + if(APPLE) + set_property( + TEST "CUnit_${suite}_${test}" + PROPERTY ENVIRONMENT "DYLD_LIBRARY_PATH=${CUNIT_LIBRARY_DIR}:$ENV{DYLD_LIBRARY_PATH}") + endif() + if(WIN32 AND ${CUNIT_LIBRARY_TYPE} STREQUAL "SHARED_LIBRARY") + set_property( + TEST "CUnit_${suite}_${test}" + PROPERTY ENVIRONMENT "PATH=${CUNIT_LIBRARY_DIR};$ENV{PATH}") + endif() endforeach() set(root "${CUNIT_DIR}") diff --git a/src/cmake/modules/Criterion.cmake b/src/cmake/modules/Criterion.cmake index 90e809c..01a9602 100644 --- a/src/cmake/modules/Criterion.cmake +++ b/src/cmake/modules/Criterion.cmake @@ -16,6 +16,13 @@ include(Glob) set(_criterion_dir "${CMAKE_CURRENT_LIST_DIR}/Criterion") function(add_criterion_executable _target) + # Retrieve location of shared libary, which is need to extend the PATH + # environment variable on Microsoft Windows, so that the operating + # system can locate the .dll that it was linked against. + get_target_property(CRITERION_LIBRARY_TYPE Criterion TYPE) + get_target_property(CRITERION_IMPORTED_LOCATION Criterion IMPORTED_LOCATION) + get_filename_component(CRITERION_LIBRARY_DIR "${CRITERION_IMPORTED_LOCATION}" PATH) + set(s "[ \t\r\n]") # space set(w "[0-9a-zA-Z_]") # word set(b "[^0-9a-zA-Z_]") # boundary @@ -73,6 +80,16 @@ function(add_criterion_executable _target) add_test( NAME "Criterion_${_suite}_${_name}" COMMAND ${_target} --suite ${_suite} --test ${_name} --cunit=${_suite}-${_name} --quiet) + if(APPLE) + set_property( + TEST "Criterion_${_suite}_${_name}" + PROPERTY ENVIRONMENT "DYLD_LIBRARY_PATH=${CRITERION_LIBRARY_DIR}:$ENV{DYLD_LIBRARY_PATH}") + endif() + if(WIN32 AND ${CRITERION_LIBRARY_TYPE} STREQUAL "SHARED_LIBRARY") + set_property( + TEST "Criterion_${_suite}_${_name}" + PROPERTY ENVIRONMENT "PATH=${CRITERION_LIBRARY_DIR};$ENV{PATH}") + endif() endforeach() endfunction() diff --git a/src/cmake/modules/FindCUnit.cmake b/src/cmake/modules/FindCUnit.cmake index 17a8f05..5b19165 100644 --- a/src/cmake/modules/FindCUnit.cmake +++ b/src/cmake/modules/FindCUnit.cmake @@ -9,12 +9,14 @@ # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -find_path(CUNIT_INC CUnit/CUnit.h) -find_library(CUNIT_LIB cunit) +set(CUNIT_HEADER "CUnit/CUnit.h") -if(CUNIT_INC AND EXISTS "${CUNIT_INC}/CUnit/CUnit.h") - set(PATTERN "^#define CU_VERSION \"([0-9]+)\.([0-9]+)\-([0-9]+)\"$") - file(STRINGS "${CUNIT_INC}/CUnit/CUnit.h" CUNIT_H REGEX "${PATTERN}") +find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER}) +mark_as_advanced(CUNIT_INCLUDE_DIR) + +if(CUNIT_INCLUDE_DIR AND EXISTS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}") + set(PATTERN "^#define CU_VERSION \"([0-9]+)\\.([0-9]+)\\-([0-9]+)\"$") + file(STRINGS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}" CUNIT_H REGEX "${PATTERN}") string(REGEX REPLACE "${PATTERN}" "\\1" CUNIT_VERSION_MAJOR "${CUNIT_H}") string(REGEX REPLACE "${PATTERN}" "\\2" CUNIT_VERSION_MINOR "${CUNIT_H}") @@ -23,16 +25,57 @@ if(CUNIT_INC AND EXISTS "${CUNIT_INC}/CUnit/CUnit.h") set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}-${CUNIT_VERSION_PATCH}") endif() +find_library(CUNIT_LIBRARY cunit) + include(FindPackageHandleStandardArgs) find_package_handle_standard_args( CUnit REQUIRED_VARS - CUNIT_LIB CUNIT_INC - VERSION_VAR CUNIT_VERSION) + CUNIT_LIBRARY CUNIT_INCLUDE_DIR + VERSION_VAR + CUNIT_VERSION) -if(CUNIT_FOUND AND NOT TARGET CUnit) - add_library(CUnit INTERFACE IMPORTED) +if(CUNIT_FOUND) + set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR}) + set(CUNIT_LIBRARIES ${CUNIT_LIBRARY}) - set_property(TARGET CUnit PROPERTY INTERFACE_LINK_LIBRARIES "${CUNIT_LIB}") - set_property(TARGET CUnit PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CUNIT_INC}") + if(WIN32) + get_filename_component(CUNIT_LIBRARY_DIR "${CUNIT_LIBRARY}}" PATH) + get_filename_component(CUNIT_BASENAME "${CUNIT_LIBRARY}}" NAME_WE) + get_filename_component(CUNIT_PREFIX "${CUNIT_LIBRARY_DIR}" PATH) + + find_program( + CUNIT_DLL + "${CMAKE_SHARED_LIBRARY_PREFIX}${CUNIT_BASENAME}${CMAKE_SHARED_LIBRARY_SUFFIX}" + HINTS + ${CUNIT_PREFIX} + PATH_SUFFIXES + bin + NO_DEFAULT_PATH) + mark_as_advanced(CUNIT_DLL) + + # IMPORTANT: + # Providing a .dll file as the value for IMPORTED_LOCATION can only be + # done for "SHARED" libraries, otherwise the location of the .dll will be + # passed to linker, causing it to fail. + if(CUNIT_DLL) + add_library(CUnit SHARED IMPORTED) + set_target_properties( + CUnit PROPERTIES IMPORTED_IMPLIB "${CUNIT_LIBRARY}") + set_target_properties( + CUnit PROPERTIES IMPORTED_LOCATION "${CUNIT_DLL}") + else() + add_library(CUnit STATIC IMPORTED) + set_target_properties( + CUnit PROPERTIES IMPORTED_LOCATION "${CUNIT_LIBRARY}") + endif() + else() + add_library(CUnit UNKNOWN IMPORTED) + set_target_properties( + CUnit PROPERTIES IMPORTED_LOCATION "${CUNIT_LIBRARY}") + endif() + + set_target_properties( + CUnit PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CUNIT_INCLUDE_DIR}") endif() + diff --git a/src/cmake/modules/FindCriterion.cmake b/src/cmake/modules/FindCriterion.cmake index 0108766..19cb871 100644 --- a/src/cmake/modules/FindCriterion.cmake +++ b/src/cmake/modules/FindCriterion.cmake @@ -9,16 +9,53 @@ # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -find_path(CRITERION_INC criterion/criterion.h PATH_SUFFIXES criterion) -find_library(CRITERION_LIB criterion) +find_path(CRITERION_INCLUDE_DIR criterion/criterion.h) +find_library(CRITERION_LIBRARY criterion) + +mark_as_advanced(CRITERION_INCLUDE_DIR) + +# Criterion does not define the version number anywhere. include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Criterion DEFAULT_MSG CRITERION_LIB CRITERION_INC) +find_package_handle_standard_args(Criterion DEFAULT_MSG CRITERION_LIBRARY CRITERION_INCLUDE_DIR) -if (CRITERION_FOUND AND NOT TARGET Criterion) - add_library(Criterion INTERFACE IMPORTED) +if(CRITERION_FOUND) + set(CRITERION_INCLUDE_DIRS ${CRITERION_INCLUDE_DIR}) + set(CRITERION_LIBRARIES ${CRITERION_LIBRARY}) - set_property(TARGET Criterion PROPERTY INTERFACE_LINK_LIBRARIES "${CRITERION_LIB}") - set_property(TARGET Criterion PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CRITERION_INC}") + if(WIN32) + get_filename_component(CRITERION_LIBRARY_DIR "${CRITERION_LIBRARY}}" PATH) + get_filename_component(CRITERION_BASENAME "${CRITERION_LIBRARY}}" NAME_WE) + get_filename_component(CRITERION_PREFIX "${CRITERION_LIBRARY_DIR}" PATH) + + find_program( + CRITERION_DLL + "${CMAKE_SHARED_LIBRARY_PREFIX}${CRITERION_BASENAME}${CMAKE_SHARED_LIBRARY_SUFFIX}" + HINTS + ${CRITERION_PREFIX} + PATH_SUFFIXES + bin + NO_DEFAULT_PATH) + mark_as_advanced(CRITERION_DLL) + + if(CRITERION_DLL) + add_library(Criterion SHARED IMPORTED) + set_target_properties( + Criterion PROPERTIES IMPORTED_IMPLIB "${CRITERION_LIBRARY}") + set_target_properties( + Criterion PROPERTIES IMPORTED_LOCATION "${CRITERION_DLL}") + else() + add_library(Criterion STATIC IMPORTED) + set_target_properties( + Criterion PROPERTIES IMPORTED_LOCATION "${CRITERION_LIBRARY}") + endif() + else() + add_library(Criterion UNKNOWN IMPORTED) + set_target_properties( + Criterion PROPERTIES IMPORTED_LOCATION "${CRITERION_LIBRARY}") + endif() + + set_target_properties( + Criterion PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CRITERION_INCLUDE_DIR}") endif()