From 9cb68b1cd408165d00449c2fed80f2f156d2b80b Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 24 Sep 2012 10:27:09 -0400 Subject: [PATCH] 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. --- Tests/CMakeOnly/find_library/CMakeLists.txt | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Tests/CMakeOnly/find_library/CMakeLists.txt b/Tests/CMakeOnly/find_library/CMakeLists.txt index 08f9331e1..9120f69ba 100644 --- a/Tests/CMakeOnly/find_library/CMakeLists.txt +++ b/Tests/CMakeOnly/find_library/CMakeLists.txt @@ -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()