2024-10-27 14:32:53 +00:00
|
|
|
#[=======================================================================[.rst:
|
|
|
|
|
FindBluelib
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
Find the Bluelib library and header directories
|
|
|
|
|
|
|
|
|
|
Imported Targets
|
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
This module defines the following :prop_tgt:`IMPORTED` target:
|
|
|
|
|
|
|
|
|
|
``Bluelib::Bluelib``
|
|
|
|
|
The Bluelib library, if found
|
|
|
|
|
|
|
|
|
|
Result Variables
|
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
This module will set the following variables in your project:
|
|
|
|
|
|
|
|
|
|
``Bluelib_FOUND``
|
|
|
|
|
true if the Bluelib C headers and libraries were found
|
|
|
|
|
``Bluelib_INCLUDE_DIR``
|
|
|
|
|
directories containing the Bluelib C headers.
|
|
|
|
|
|
|
|
|
|
``Bluelib_LIBRARY``
|
|
|
|
|
the C library to link against
|
|
|
|
|
|
|
|
|
|
Hints
|
|
|
|
|
^^^^^
|
|
|
|
|
|
|
|
|
|
The user may set the environment variable ``Bluelib_PREFIX`` to the root
|
|
|
|
|
directory of a Bluelib library installation.
|
|
|
|
|
#]=======================================================================]
|
|
|
|
|
|
|
|
|
|
set (Bluelib_SEARCH_PATHS
|
|
|
|
|
~/Library/Frameworks
|
|
|
|
|
/Library/Frameworks
|
|
|
|
|
/usr/local
|
|
|
|
|
/usr/local/share
|
|
|
|
|
/usr
|
|
|
|
|
/sw # Fink
|
|
|
|
|
/opt/local # DarwinPorts
|
|
|
|
|
/opt/csw # Blastwave
|
|
|
|
|
/opt
|
|
|
|
|
${Bluelib_PREFIX}
|
|
|
|
|
$ENV{Bluelib_PREFIX})
|
|
|
|
|
|
|
|
|
|
if (Bluelib_STATIC)
|
|
|
|
|
set(_lib_suffix "-s")
|
|
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
set(supported_components Core Ds Term Cmd Io Serial Compress)
|
2024-10-27 14:32:53 +00:00
|
|
|
set(components ${Bluelib_FIND_COMPONENTS})
|
|
|
|
|
string(REPLACE ";" ", " supported_components_string_list "${supported_components}")
|
|
|
|
|
|
|
|
|
|
if (NOT components)
|
|
|
|
|
set(components ${supported_components})
|
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
set(required_vars)
|
|
|
|
|
|
|
|
|
|
foreach (component ${components})
|
|
|
|
|
if (NOT "${component}" IN_LIST supported_components)
|
|
|
|
|
message(FATAL_ERROR "'${component}' is not a valid Bluelib module.\nSupported modules: ${supported_components_string_list}")
|
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
string(TOLOWER ${component} header_name)
|
|
|
|
|
set(lib_name ${header_name}${_lib_suffix})
|
|
|
|
|
|
|
|
|
|
if (NOT Bluelib_${component}_INCLUDE_DIR)
|
|
|
|
|
find_path(Bluelib_${component}_INCLUDE_DIR
|
|
|
|
|
NAMES blue/${header_name}.h ${Bluelib_FIND_ARGS}
|
|
|
|
|
PATH_SUFFIXES include
|
|
|
|
|
PATHS ${Bluelib_SEARCH_PATHS})
|
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
if (NOT Bluelib_${component}_LIBRARY)
|
|
|
|
|
find_library(Bluelib_${component}_LIBRARY
|
|
|
|
|
NAMES blue-${lib_name} ${Bluelib_FIND_ARGS}
|
|
|
|
|
PATH_SUFFIXES lib
|
|
|
|
|
PATHS ${Bluelib_SEARCH_PATHS})
|
|
|
|
|
else ()
|
|
|
|
|
# on Windows, ensure paths are in canonical format (forward slahes):
|
|
|
|
|
file(TO_CMAKE_PATH "${Bluelib_${component}_LIBRARY}" Bluelib_${component}_LIBRARY)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
list(APPEND required_vars Bluelib_${component}_INCLUDE_DIR Bluelib_${component}_LIBRARY)
|
|
|
|
|
endforeach (component)
|
|
|
|
|
|
|
|
|
|
unset(Bluelib_FIND_ARGS)
|
|
|
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
|
|
|
|
|
|
find_package_handle_standard_args(Bluelib
|
|
|
|
|
REQUIRED_VARS ${required_vars})
|
|
|
|
|
|
|
|
|
|
if (Bluelib_FOUND)
|
2024-10-31 19:35:18 +00:00
|
|
|
set(created_targets)
|
2024-10-27 14:32:53 +00:00
|
|
|
foreach (component ${components})
|
|
|
|
|
string(TOLOWER ${component} header_name)
|
|
|
|
|
set(lib_name ${header_name}${_lib_suffix})
|
|
|
|
|
|
|
|
|
|
if(NOT TARGET Bluelib::${component})
|
|
|
|
|
add_library(Bluelib::${component} UNKNOWN IMPORTED)
|
|
|
|
|
set_target_properties(Bluelib::${component} PROPERTIES
|
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${Bluelib_${component}_INCLUDE_DIR}")
|
|
|
|
|
target_compile_definitions(Bluelib::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
|
|
|
|
|
|
2024-11-14 21:57:40 +00:00
|
|
|
if (Bluelib_STATIC)
|
|
|
|
|
target_compile_definitions(Bluelib::${component} INTERFACE BLUELIB_STATIC=1)
|
|
|
|
|
endif ()
|
|
|
|
|
|
2024-10-27 14:32:53 +00:00
|
|
|
set_target_properties(Bluelib::${component} PROPERTIES
|
|
|
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
|
|
|
IMPORTED_LOCATION "${Bluelib_${component}_LIBRARY}")
|
2024-10-31 19:35:18 +00:00
|
|
|
set(created_targets ${created_targets} ${component})
|
|
|
|
|
endif ()
|
|
|
|
|
endforeach (component)
|
|
|
|
|
|
|
|
|
|
foreach (component ${created_targets})
|
2025-08-09 19:57:42 +01:00
|
|
|
if ("${component}" STREQUAL "Ds")
|
2024-10-31 19:35:18 +00:00
|
|
|
if (NOT TARGET Bluelib::Core)
|
2025-08-09 19:57:42 +01:00
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Ds' depends on 'Core', which was not specified in find_package()")
|
2024-10-31 19:35:18 +00:00
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
target_link_libraries(Bluelib::Ds INTERFACE Bluelib::Core)
|
2024-10-31 19:35:18 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
if ("${component}" STREQUAL "Term")
|
|
|
|
|
if (NOT TARGET Bluelib::Core)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Core', which was not specified in find_package()")
|
|
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
if (NOT TARGET Bluelib::Ds)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Ds', which was not specified in find_package()")
|
2024-10-31 19:35:18 +00:00
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Ds)
|
2024-10-31 19:35:18 +00:00
|
|
|
endif ()
|
|
|
|
|
|
2025-06-27 22:00:26 +01:00
|
|
|
if ("${component}" STREQUAL "Serial")
|
|
|
|
|
if (NOT TARGET Bluelib::Core)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Core', which was not specified in find_package()")
|
|
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
if (NOT TARGET Bluelib::Ds)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Ds', which was not specified in find_package()")
|
2025-06-27 22:00:26 +01:00
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Ds)
|
2025-06-27 22:00:26 +01:00
|
|
|
endif ()
|
|
|
|
|
|
2024-10-31 19:35:18 +00:00
|
|
|
if ("${component}" STREQUAL "Cmd")
|
|
|
|
|
if (NOT TARGET Bluelib::Core)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Core', which was not specified in find_package()")
|
|
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
if (NOT TARGET Bluelib::Ds)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Ds', which was not specified in find_package()")
|
2024-10-31 19:35:18 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
if (NOT TARGET Bluelib::Term)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
|
|
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Ds Bluelib::Term)
|
2024-10-27 14:32:53 +00:00
|
|
|
endif ()
|
2025-04-11 14:02:02 +01:00
|
|
|
|
|
|
|
|
if ("${component}" STREQUAL "Io")
|
|
|
|
|
if (NOT TARGET Bluelib::Core)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Core', which was not specified in find_package()")
|
|
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
if (NOT TARGET Bluelib::Ds)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Ds', which was not specified in find_package()")
|
2025-04-11 14:02:02 +01:00
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Ds)
|
2025-04-11 14:02:02 +01:00
|
|
|
endif ()
|
2025-07-28 22:29:13 +01:00
|
|
|
|
|
|
|
|
if ("${component}" STREQUAL "Compress")
|
|
|
|
|
if (NOT TARGET Bluelib::Core)
|
|
|
|
|
message(FATAL_ERROR "Bluelib: Module 'Compress' depends on 'Core', which was not specified in find_package()")
|
|
|
|
|
endif ()
|
|
|
|
|
|
2025-08-09 19:57:42 +01:00
|
|
|
target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Ds)
|
2025-07-28 22:29:13 +01:00
|
|
|
endif ()
|
2024-10-27 14:32:53 +00:00
|
|
|
endforeach (component)
|
|
|
|
|
endif()
|