2012-07-20 18:19:16 +04:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
project(FindLibraryTest NONE)
|
|
|
|
|
|
|
|
set(CMAKE_FIND_DEBUG_MODE 1)
|
|
|
|
|
2012-09-24 18:27:09 +04:00
|
|
|
macro(test_find_library desc expected)
|
2012-07-20 18:19:16 +04:00
|
|
|
unset(LIB CACHE)
|
2012-09-24 18:27:09 +04:00
|
|
|
find_library(LIB ${ARGN} NO_DEFAULT_PATH)
|
2012-07-20 18:19:16 +04:00
|
|
|
if(LIB)
|
|
|
|
# Convert to relative path for comparison to expected location.
|
|
|
|
file(RELATIVE_PATH REL_LIB "${CMAKE_CURRENT_SOURCE_DIR}" "${LIB}")
|
|
|
|
|
|
|
|
# Check and report failure.
|
|
|
|
if(NOT "${REL_LIB}" STREQUAL "${expected}")
|
2012-09-24 18:27:09 +04:00
|
|
|
message(SEND_ERROR "Library ${expected} found as [${REL_LIB}]${desc}")
|
|
|
|
elseif(CMAKE_FIND_DEBUG_MODE)
|
|
|
|
message(STATUS "Library ${expected} found as [${REL_LIB}]${desc}")
|
2012-07-20 18:19:16 +04:00
|
|
|
endif()
|
|
|
|
else()
|
2012-09-24 18:27:09 +04:00
|
|
|
message(SEND_ERROR "Library ${expected} NOT FOUND${desc}")
|
2012-07-20 18:19:16 +04:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2012-09-24 18:27:09 +04:00
|
|
|
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()
|
|
|
|
|
2012-07-20 18:19:16 +04:00
|
|
|
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
2016-06-10 17:11:18 +03:00
|
|
|
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE)
|
2012-07-20 18:19:16 +04:00
|
|
|
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
|
|
|
|
|
|
|
|
set(CMAKE_SIZEOF_VOID_P 4)
|
|
|
|
foreach(lib
|
2016-06-10 17:11:18 +03:00
|
|
|
lib/32/libtest5.a
|
2012-07-20 18:19:16 +04:00
|
|
|
lib/A/lib/libtest1.a
|
2016-06-10 17:11:18 +03:00
|
|
|
lib/A/lib32/libtest3.a
|
2012-07-20 18:19:16 +04:00
|
|
|
lib/A/libtest1.a
|
|
|
|
lib/libtest1.a
|
|
|
|
lib/libtest2.a
|
|
|
|
lib/libtest3.a
|
|
|
|
lib/libtest3.a
|
2016-06-10 17:11:18 +03:00
|
|
|
lib32/A/lib/libtest2.a
|
|
|
|
lib32/A/lib32/libtest4.a
|
|
|
|
lib32/A/libtest4.a
|
|
|
|
lib32/libtest4.a
|
2012-07-20 18:19:16 +04:00
|
|
|
)
|
2012-09-24 18:27:09 +04:00
|
|
|
test_find_library_subst(${lib})
|
2012-07-20 18:19:16 +04:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(CMAKE_SIZEOF_VOID_P 8)
|
|
|
|
foreach(lib64
|
|
|
|
lib/64/libtest2.a
|
2012-07-20 22:09:57 +04:00
|
|
|
lib/A/lib64/libtest3.a
|
2012-07-20 18:19:16 +04:00
|
|
|
lib/libtest3.a
|
2012-07-20 22:09:57 +04:00
|
|
|
lib64/A/lib/libtest2.a
|
2012-07-20 18:19:16 +04:00
|
|
|
lib64/A/lib64/libtest1.a
|
|
|
|
lib64/A/libtest1.a
|
|
|
|
lib64/libtest1.a
|
|
|
|
)
|
2012-09-24 18:27:09 +04:00
|
|
|
test_find_library_subst(${lib64})
|
2012-07-20 18:19:16 +04:00
|
|
|
endforeach()
|
2012-09-24 19:05:10 +04:00
|
|
|
|
|
|
|
test_find_library("" A/libtestA.a
|
|
|
|
NAMES testA testB
|
|
|
|
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B
|
|
|
|
)
|
|
|
|
test_find_library("" B/libtestB.a
|
|
|
|
NAMES testB testA
|
|
|
|
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B
|
|
|
|
)
|
|
|
|
test_find_library("" A/libtestA.a
|
|
|
|
NAMES testB testA NAMES_PER_DIR
|
|
|
|
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B
|
|
|
|
)
|