set DYLD_LIBRARY_PATH (macOS) and PATH (Windows) in test environment if linked against shared libraries
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
parent
085985dce7
commit
977458c57a
4 changed files with 133 additions and 18 deletions
|
@ -16,6 +16,14 @@ include(Glob)
|
||||||
set(CUNIT_DIR "${CMAKE_CURRENT_LIST_DIR}/CUnit")
|
set(CUNIT_DIR "${CMAKE_CURRENT_LIST_DIR}/CUnit")
|
||||||
|
|
||||||
function(add_cunit_executable target)
|
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
|
# Generate semi-random filename to store the generated code in to avoid
|
||||||
# possible naming conflicts.
|
# possible naming conflicts.
|
||||||
string(RANDOM random)
|
string(RANDOM random)
|
||||||
|
@ -114,6 +122,16 @@ function(add_cunit_executable target)
|
||||||
add_test(
|
add_test(
|
||||||
NAME "CUnit_${suite}_${test}"
|
NAME "CUnit_${suite}_${test}"
|
||||||
COMMAND ${target} -a -r "${suite}-${test}" -s ${suite} -t ${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()
|
endforeach()
|
||||||
|
|
||||||
set(root "${CUNIT_DIR}")
|
set(root "${CUNIT_DIR}")
|
||||||
|
|
|
@ -16,6 +16,13 @@ include(Glob)
|
||||||
set(_criterion_dir "${CMAKE_CURRENT_LIST_DIR}/Criterion")
|
set(_criterion_dir "${CMAKE_CURRENT_LIST_DIR}/Criterion")
|
||||||
|
|
||||||
function(add_criterion_executable _target)
|
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(s "[ \t\r\n]") # space
|
||||||
set(w "[0-9a-zA-Z_]") # word
|
set(w "[0-9a-zA-Z_]") # word
|
||||||
set(b "[^0-9a-zA-Z_]") # boundary
|
set(b "[^0-9a-zA-Z_]") # boundary
|
||||||
|
@ -73,6 +80,16 @@ function(add_criterion_executable _target)
|
||||||
add_test(
|
add_test(
|
||||||
NAME "Criterion_${_suite}_${_name}"
|
NAME "Criterion_${_suite}_${_name}"
|
||||||
COMMAND ${_target} --suite ${_suite} --test ${_name} --cunit=${_suite}-${_name} --quiet)
|
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()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,14 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||||
#
|
#
|
||||||
find_path(CUNIT_INC CUnit/CUnit.h)
|
set(CUNIT_HEADER "CUnit/CUnit.h")
|
||||||
find_library(CUNIT_LIB cunit)
|
|
||||||
|
|
||||||
if(CUNIT_INC AND EXISTS "${CUNIT_INC}/CUnit/CUnit.h")
|
find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER})
|
||||||
set(PATTERN "^#define CU_VERSION \"([0-9]+)\.([0-9]+)\-([0-9]+)\"$")
|
mark_as_advanced(CUNIT_INCLUDE_DIR)
|
||||||
file(STRINGS "${CUNIT_INC}/CUnit/CUnit.h" CUNIT_H REGEX "${PATTERN}")
|
|
||||||
|
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}" "\\1" CUNIT_VERSION_MAJOR "${CUNIT_H}")
|
||||||
string(REGEX REPLACE "${PATTERN}" "\\2" CUNIT_VERSION_MINOR "${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}")
|
set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}-${CUNIT_VERSION_PATCH}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_library(CUNIT_LIBRARY cunit)
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(
|
find_package_handle_standard_args(
|
||||||
CUnit
|
CUnit
|
||||||
REQUIRED_VARS
|
REQUIRED_VARS
|
||||||
CUNIT_LIB CUNIT_INC
|
CUNIT_LIBRARY CUNIT_INCLUDE_DIR
|
||||||
VERSION_VAR CUNIT_VERSION)
|
VERSION_VAR
|
||||||
|
CUNIT_VERSION)
|
||||||
|
|
||||||
if(CUNIT_FOUND AND NOT TARGET CUnit)
|
if(CUNIT_FOUND)
|
||||||
add_library(CUnit INTERFACE IMPORTED)
|
set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR})
|
||||||
|
set(CUNIT_LIBRARIES ${CUNIT_LIBRARY})
|
||||||
|
|
||||||
set_property(TARGET CUnit PROPERTY INTERFACE_LINK_LIBRARIES "${CUNIT_LIB}")
|
if(WIN32)
|
||||||
set_property(TARGET CUnit PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CUNIT_INC}")
|
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()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -9,16 +9,53 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||||
#
|
#
|
||||||
find_path(CRITERION_INC criterion/criterion.h PATH_SUFFIXES criterion)
|
find_path(CRITERION_INCLUDE_DIR criterion/criterion.h)
|
||||||
find_library(CRITERION_LIB criterion)
|
find_library(CRITERION_LIBRARY criterion)
|
||||||
|
|
||||||
|
mark_as_advanced(CRITERION_INCLUDE_DIR)
|
||||||
|
|
||||||
|
# Criterion does not define the version number anywhere.
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
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)
|
if(CRITERION_FOUND)
|
||||||
add_library(Criterion INTERFACE IMPORTED)
|
set(CRITERION_INCLUDE_DIRS ${CRITERION_INCLUDE_DIR})
|
||||||
|
set(CRITERION_LIBRARIES ${CRITERION_LIBRARY})
|
||||||
|
|
||||||
set_property(TARGET Criterion PROPERTY INTERFACE_LINK_LIBRARIES "${CRITERION_LIB}")
|
if(WIN32)
|
||||||
set_property(TARGET Criterion PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CRITERION_INC}")
|
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()
|
endif()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue