2016-11-10 23:24:09 +01:00
|
|
|
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
|
|
|
|
|
2018-02-21 23:00:32 +01:00
|
|
|
# prevent multiple inclusion
|
2019-02-06 17:30:52 +01:00
|
|
|
if (DEFINED THIRD_PARTY_MODULE_LOADED)
|
2018-02-21 23:00:32 +01:00
|
|
|
return()
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
set(THIRD_PARTY_MODULE_LOADED YES)
|
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (save_default_library_suffixes)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(DEFAULT_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
2019-02-06 17:30:52 +01:00
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (restore_default_library_suffixes)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${DEFAULT_CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
unset(DEFAULT_CMAKE_FIND_LIBRARY_SUFFIXES)
|
2019-02-06 17:30:52 +01:00
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (configure_static_library_suffixes)
|
2018-02-21 23:00:32 +01:00
|
|
|
# allows to look for static libraries in particular
|
2019-02-06 17:30:52 +01:00
|
|
|
if (WIN32)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
|
2019-02-06 17:30:52 +01:00
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (configure_dynamic_library_suffixes)
|
2018-02-21 23:00:32 +01:00
|
|
|
# allows to look for dynamic libraries in particular
|
2019-02-06 17:30:52 +01:00
|
|
|
if (WIN32)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .dll .dll.a)
|
2019-02-06 17:30:52 +01:00
|
|
|
elseif (APPLE)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .dylib .so)
|
2019-02-06 17:30:52 +01:00
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .so)
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (link_against_library_varnames
|
|
|
|
NAME
|
|
|
|
LINKAGE
|
|
|
|
REQUIRED
|
|
|
|
PRIVATE_LIBRARIES_VARNAME
|
|
|
|
PUBLIC_LIBRARIES_VARNAME
|
|
|
|
PRIVATE_STATIC_LIBRARIES_VARNAME
|
|
|
|
PUBLIC_STATIC_LIBRARIES_VARNAME)
|
|
|
|
# determine whether the library is required or optional FIXME: improve passing required argument
|
|
|
|
if ("${REQUIRED}" STREQUAL "OPTIONAL")
|
2018-02-21 23:00:32 +01:00
|
|
|
set(${NAME}_REQUIRED "NO")
|
2019-02-06 17:30:52 +01:00
|
|
|
elseif ("${REQUIRED}" STREQUAL "REQUIRED")
|
2018-02-21 23:00:32 +01:00
|
|
|
set(${NAME}_REQUIRED "REQUIRED")
|
2019-02-06 17:30:52 +01:00
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
message(FATAL_ERROR "Invalid use of link_against_library; must specify either REQUIRED or OPTIONAL.")
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
# add library to list of libraries to link against when building dynamic libraries or applications - prefer dynamic lib
|
|
|
|
# if linkage not explicitely specified
|
|
|
|
if (${NAME}_STATIC_LIB
|
|
|
|
AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE"
|
|
|
|
AND ((NOT (${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB))
|
|
|
|
OR (STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application")
|
|
|
|
OR (STATIC_LIBRARY_LINKAGE
|
|
|
|
AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library"))))
|
|
|
|
OR ("${LINKAGE}" STREQUAL "STATIC")))
|
2018-02-21 23:00:32 +01:00
|
|
|
set(USE_${NAME} ON)
|
|
|
|
set(USE_STATIC_${NAME} ON)
|
|
|
|
list(APPEND LIBRARIES ${${NAME}_STATIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} statically against external library ${NAME} (${${NAME}_STATIC_LIB})."
|
|
|
|
)
|
|
|
|
if (${NAME}_STATIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ADDITIONAL_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Adding include path for ${NAME} to ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_STATIC_INCLUDE_DIR}"
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
if (${NAME}_STATIC_COMPILE_DEFINITIONS)
|
2018-10-21 20:24:55 +02:00
|
|
|
list(APPEND META_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS ${${NAME}_STATIC_COMPILE_DEFINITIONS})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2016-07-22 01:35:32 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PUBLIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_STATIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PUBLIC_SHARED_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PRIVATE_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_STATIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PRIVATE_SHARED_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2017-07-04 22:44:32 +02:00
|
|
|
|
2018-02-21 23:00:32 +01:00
|
|
|
# add Qt resources of static library to be enabled
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_QT_RESOURCES)
|
2018-02-21 23:00:32 +01:00
|
|
|
message(STATUS "Adding ${${NAME}_QT_RESOURCES} to LIBRARIES_QT_RESOURCES for ${META_PROJECT_NAME}.")
|
|
|
|
list(APPEND LIBRARIES_QT_RESOURCES ${${NAME}_QT_RESOURCES})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2017-07-04 22:44:32 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
elseif ((${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB)
|
|
|
|
AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${LINKAGE}" STREQUAL "SHARED")))
|
2018-02-21 23:00:32 +01:00
|
|
|
set(USE_${NAME} ON)
|
|
|
|
set(USE_SHARED_${NAME} ON)
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT ${NAME}_DYNAMIC_LIB)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(${NAME}_DYNAMIC_LIB ${${NAME}_SHARED_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND LIBRARIES ${${NAME}_DYNAMIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} dynamically against external library ${NAME} (${${NAME}_DYNAMIC_LIB})."
|
|
|
|
)
|
|
|
|
if (${NAME}_DYNAMIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ADDITIONAL_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Adding include path for ${NAME} to ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_DYNAMIC_INCLUDE_DIR}"
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
if (${NAME}_DYNAMIC_COMPILE_DEFINITIONS)
|
2018-10-21 20:24:55 +02:00
|
|
|
list(APPEND META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS ${${NAME}_DYNAMIC_COMPILE_DEFINITIONS})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2017-08-31 02:11:17 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${${NAME}_DYNAMIC_LIB} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PUBLIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_DYNAMIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PUBLIC_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PRIVATE_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_DYNAMIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PRIVATE_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
else ()
|
|
|
|
if (${NAME}_REQUIRED)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
|
|
|
|
)
|
|
|
|
else ()
|
|
|
|
message(
|
|
|
|
WARNING
|
|
|
|
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
# add library to list of libraries to be provided as transitive dependencies when building static libraries - prefer
|
|
|
|
# static lib if linkage not explicitely specified
|
|
|
|
if (${NAME}_STATIC_LIB AND ("${LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${LINKAGE}" STREQUAL "STATIC"))
|
2018-02-21 23:00:32 +01:00
|
|
|
set(USE_${NAME} ON)
|
|
|
|
set(USE_STATIC_${NAME} ON)
|
|
|
|
list(APPEND STATIC_LIBRARIES ${${NAME}_STATIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Adding static external library ${NAME} (${${NAME}_STATIC_LIB}) to dependencies of ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}."
|
|
|
|
)
|
|
|
|
if (${NAME}_STATIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ADDITIONAL_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Adding include path for ${NAME} to static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_STATIC_INCLUDE_DIR}"
|
|
|
|
)
|
|
|
|
endif ()
|
2017-07-04 22:44:32 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PUBLIC_STATIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_STATIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PUBLIC_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PRIVATE_STATIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_STATIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PRIVATE_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2016-07-27 18:16:51 +02:00
|
|
|
|
2018-02-21 23:00:32 +01:00
|
|
|
# add Qt resources of static library for exporting it
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_QT_RESOURCES)
|
2018-02-21 23:00:32 +01:00
|
|
|
message(STATUS "Adding ${${NAME}_QT_RESOURCES} to STATIC_LIBRARIES_QT_RESOURCES for ${META_PROJECT_NAME}.")
|
|
|
|
list(APPEND STATIC_LIBRARIES_QT_RESOURCES ${${NAME}_QT_RESOURCES})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2016-08-19 16:13:41 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
elseif ((${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB)
|
|
|
|
AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE"
|
|
|
|
AND (NOT ${NAME}_STATIC_LIB
|
|
|
|
OR (NOT STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application")
|
|
|
|
OR (NOT STATIC_LIBRARY_LINKAGE
|
|
|
|
AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library"))))
|
|
|
|
OR ("${LINKAGE}" STREQUAL "SHARED")))
|
2018-02-21 23:00:32 +01:00
|
|
|
set(USE_${NAME} ON)
|
|
|
|
set(USE_SHARED_${NAME} ON)
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT ${NAME}_DYNAMIC_LIB)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(${NAME}_DYNAMIC_LIB ${${NAME}_SHARED_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND STATIC_LIBRARIES ${${NAME}_DYNAMIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Adding dynamic external library ${NAME} (${${NAME}_DYNAMIC_LIB}) to dependencies of static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}."
|
|
|
|
)
|
|
|
|
if (${NAME}_DYNAMIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ADDITIONAL_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Adding include path for ${NAME} to static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_DYNAMIC_INCLUDE_DIR}"
|
|
|
|
)
|
|
|
|
endif ()
|
2016-07-27 18:16:51 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${${NAME}_DYNAMIC_LIB} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PUBLIC_STATIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_DYNAMIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PUBLIC_STATIC_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND ${PRIVATE_STATIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
|
2019-02-06 17:30:52 +01:00
|
|
|
if (${NAME}_DYNAMIC_INCLUDE_DIR)
|
2018-02-21 23:00:32 +01:00
|
|
|
list(APPEND PRIVATE_STATIC_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
else ()
|
|
|
|
if (${NAME}_REQUIRED)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
|
|
|
|
)
|
|
|
|
else ()
|
|
|
|
message(
|
|
|
|
WARNING
|
|
|
|
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (link_against_library NAME LINKAGE REQUIRED)
|
|
|
|
link_against_library_varnames("${NAME}"
|
|
|
|
"${LINKAGE}"
|
|
|
|
"${REQUIRED}"
|
|
|
|
PRIVATE_LIBRARIES
|
|
|
|
PUBLIC_LIBRARIES
|
|
|
|
PRIVATE_STATIC_LIBRARIES
|
|
|
|
PUBLIC_STATIC_LIBRARIES)
|
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (link_tests_against_library NAME LINKAGE REQUIRED)
|
|
|
|
link_against_library_varnames("${NAME}"
|
|
|
|
"${LINKAGE}"
|
|
|
|
"${REQUIRED}"
|
|
|
|
TEST_LIBRARIES
|
|
|
|
TEST_LIBRARIES
|
|
|
|
STATIC_TEST_LIBRARIES
|
|
|
|
STATIC_TEST_LIBRARIES)
|
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (find_external_library NAME LINKAGE REQUIRED)
|
2018-02-21 23:00:32 +01:00
|
|
|
set(${NAME}_DYNAMIC_INCLUDE_DIR NOTFOUND CACHE PATH "${NAME} include dir (dynamic)")
|
|
|
|
set(${NAME}_DYNAMIC_LIB NOTFOUND CACHE FILEPATH "${NAME} lib (dynamic)")
|
|
|
|
set(${NAME}_STATIC_INCLUDE_DIR NOTFOUND CACHE PATH "${NAME} include dir (static)")
|
|
|
|
set(${NAME}_STATIC_LIB NOTFOUND CACHE FILEPATH "${NAME} lib (static)")
|
|
|
|
|
|
|
|
save_default_library_suffixes()
|
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT ${NAME}_DYNAMIC_LIB)
|
2018-02-21 23:00:32 +01:00
|
|
|
configure_dynamic_library_suffixes()
|
|
|
|
find_library(DETECTED_${NAME}_DYNAMIC_LIB ${NAME})
|
|
|
|
set(${NAME}_DYNAMIC_LIB ${DETECTED_${NAME}_DYNAMIC_LIB} CACHE FILEPATH "${NAME} lib (dynamic)" FORCE)
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2017-02-11 02:30:46 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT ${NAME}_STATIC_LIB)
|
2018-02-21 23:00:32 +01:00
|
|
|
configure_static_library_suffixes()
|
|
|
|
find_library(DETECTED_${NAME}_STATIC_LIB ${NAME})
|
|
|
|
set(${NAME}_STATIC_LIB ${DETECTED_${NAME}_STATIC_LIB} CACHE FILEPATH "${NAME} lib (static)" FORCE)
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
|
|
|
restore_default_library_suffixes()
|
2019-02-06 17:30:52 +01:00
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (use_external_library NAME LINKAGE REQUIRED)
|
2018-02-21 23:00:32 +01:00
|
|
|
find_external_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
|
|
|
|
link_against_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
|
2019-02-06 17:30:52 +01:00
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
function (use_external_library_from_package_dynamic NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
|
2018-02-21 23:00:32 +01:00
|
|
|
# internally used by find_external_library_from_package to find dynamic libraries
|
|
|
|
configure_dynamic_library_suffixes()
|
|
|
|
find_package(${PKGNAME} ${COMPAT_VERSION})
|
|
|
|
set(${NAME}_DYNAMIC_INCLUDE_DIR ${${INCLUDE_VAR}} CACHE PATH "${NAME} include dir (dynamic)" FORCE)
|
|
|
|
set(${NAME}_DYNAMIC_LIB ${${LIBRARY_VAR}} CACHE FILEPATH "${NAME} lib (dynamic)" FORCE)
|
2019-02-06 17:30:52 +01:00
|
|
|
endfunction ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
function (use_external_library_from_package_static NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
|
2018-02-21 23:00:32 +01:00
|
|
|
# internally used by find_external_library_from_package to find static libraries
|
|
|
|
configure_static_library_suffixes()
|
|
|
|
find_package(${PKGNAME} ${COMPAT_VERSION})
|
|
|
|
set(${NAME}_STATIC_INCLUDE_DIR ${${INCLUDE_VAR}} CACHE PATH "${NAME} include dir (static)" FORCE)
|
|
|
|
set(${NAME}_STATIC_LIB ${${LIBRARY_VAR}} CACHE FILEPATH "${NAME} lib (static)" FORCE)
|
2019-02-06 17:30:52 +01:00
|
|
|
endfunction ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (find_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
|
2018-02-21 23:00:32 +01:00
|
|
|
# handle specified VERSION
|
2019-02-06 17:30:52 +01:00
|
|
|
if ("${VERSION}" STREQUAL "ANY_VERSION")
|
2018-02-21 23:00:32 +01:00
|
|
|
set(${NAME}_COMPATIBLE_VERSION "")
|
2019-02-06 17:30:52 +01:00
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
set(${NAME}_COMPATIBLE_VERSION ${VERSION})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
# use the find_library approach first because it is less buggy when trying to detect static libraries caveat: this way
|
|
|
|
# include dirs are not detected - however those are mostly the default anyways and can also be set manually by the user
|
|
|
|
# in case the auto-detection is not sufficient
|
2018-02-21 23:00:32 +01:00
|
|
|
find_external_library("${NAME}" "${LINKAGE}" OPTIONAL)
|
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
# fall back to actual use of find_package use separate functions to get a new scope
|
2018-02-21 23:00:32 +01:00
|
|
|
save_default_library_suffixes()
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT ${NAME}_DYNAMIC_LIB)
|
|
|
|
use_external_library_from_package_dynamic(${NAME}
|
|
|
|
${PKGNAME}
|
|
|
|
${INCLUDE_VAR}
|
|
|
|
"${LIBRARY_VAR}"
|
|
|
|
"${${NAME}_COMPATIBLE_VERSION}")
|
|
|
|
endif ()
|
|
|
|
if (NOT ${NAME}_STATIC_LIB)
|
|
|
|
use_external_library_from_package_static(${NAME}
|
|
|
|
${PKGNAME}
|
|
|
|
${INCLUDE_VAR}
|
|
|
|
"${LIBRARY_VAR}"
|
|
|
|
"${${NAME}_COMPATIBLE_VERSION}")
|
|
|
|
endif ()
|
2018-02-21 23:00:32 +01:00
|
|
|
restore_default_library_suffixes()
|
2019-02-06 17:30:52 +01:00
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (use_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
|
|
|
|
find_external_library_from_package("${NAME}"
|
|
|
|
"${PKGNAME}"
|
|
|
|
"${VERSION}"
|
|
|
|
"${INCLUDE_VAR}"
|
|
|
|
"${LIBRARY_VAR}"
|
|
|
|
"${LINKAGE}"
|
|
|
|
"${REQUIRED}")
|
2018-02-21 23:00:32 +01:00
|
|
|
link_against_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
|
2019-02-06 17:30:52 +01:00
|
|
|
endmacro ()
|
2018-02-21 23:00:32 +01:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
macro (use_iconv LINKAGE REQUIRED)
|
|
|
|
set(FORCE_EXTERNAL_ICONV OFF
|
|
|
|
CACHE PATH "whether to force usage of external iconv (rather than the using the one bundled with glibc)")
|
|
|
|
if (NOT FORCE_EXTERNAL_ICONV)
|
2018-02-21 23:00:32 +01:00
|
|
|
# check whether iconv exists in standard lib
|
|
|
|
include(CheckFunctionExists)
|
|
|
|
check_function_exists(iconv HAS_ICONV)
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
if (NOT FORCE_EXTERNAL_ICONV AND HAS_ICONV)
|
2018-02-21 23:00:32 +01:00
|
|
|
message(STATUS "Using iconv from the standard library for ${META_PROJECT_NAME}.")
|
2019-02-06 17:30:52 +01:00
|
|
|
else ()
|
2018-02-21 23:00:32 +01:00
|
|
|
# find external iconv library
|
|
|
|
use_external_library(iconv ${LINKAGE} ${REQUIRED})
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
endmacro ()
|