find_library: Generalize helper macro in test case

In Tests/CMakeOnly/find_library/CMakeLists.txt generalize the
test_find_library macro and move the lib64 substitution logic to a new
test_find_library_subst macro.
This commit is contained in:
Brad King 2012-09-24 10:27:09 -04:00
parent b64dd760d1
commit 9cb68b1cd4
1 changed files with 18 additions and 18 deletions

View File

@ -3,34 +3,34 @@ project(FindLibraryTest NONE)
set(CMAKE_FIND_DEBUG_MODE 1)
macro(test_find_library expected)
get_filename_component(dir ${expected} PATH)
get_filename_component(name ${expected} NAME)
string(REGEX REPLACE "lib/?64" "lib" dir "${dir}")
macro(test_find_library desc expected)
unset(LIB CACHE)
find_library(LIB
NAMES ${name}
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}
NO_DEFAULT_PATH
)
find_library(LIB ${ARGN} NO_DEFAULT_PATH)
if(LIB)
# Convert to relative path for comparison to expected location.
file(RELATIVE_PATH REL_LIB "${CMAKE_CURRENT_SOURCE_DIR}" "${LIB}")
# Debugging output.
if(CMAKE_FIND_DEBUG_MODE)
message(STATUS "Library ${expected} searched as ${dir}, found as [${REL_LIB}].")
endif()
# Check and report failure.
if(NOT "${REL_LIB}" STREQUAL "${expected}")
message(SEND_ERROR "Library ${l} should have been [${expected}] but was [${REL_LIB}]")
message(SEND_ERROR "Library ${expected} found as [${REL_LIB}]${desc}")
elseif(CMAKE_FIND_DEBUG_MODE)
message(STATUS "Library ${expected} found as [${REL_LIB}]${desc}")
endif()
else()
message(SEND_ERROR "Library ${expected} searched as ${dir}, NOT FOUND!")
message(SEND_ERROR "Library ${expected} NOT FOUND${desc}")
endif()
endmacro()
macro(test_find_library_subst expected)
get_filename_component(dir ${expected} PATH)
get_filename_component(name ${expected} NAME)
string(REGEX REPLACE "lib/?64" "lib" dir "${dir}")
test_find_library(", searched as ${dir}" "${expected}"
NAMES ${name}
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}
)
endmacro()
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
@ -44,7 +44,7 @@ foreach(lib
lib/libtest3.a
lib/libtest3.a
)
test_find_library(${lib})
test_find_library_subst(${lib})
endforeach()
set(CMAKE_SIZEOF_VOID_P 8)
@ -57,5 +57,5 @@ foreach(lib64
lib64/A/libtest1.a
lib64/libtest1.a
)
test_find_library(${lib64})
test_find_library_subst(${lib64})
endforeach()