meta: split into independent repo; add build system, frontend
This commit is contained in:
189
cmake/FindBluelib.cmake
Normal file
189
cmake/FindBluelib.cmake
Normal file
@@ -0,0 +1,189 @@
|
||||
#[=======================================================================[.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 ()
|
||||
|
||||
set(supported_components Core Ds Term Cmd Io Serial Compress)
|
||||
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)
|
||||
set(created_targets)
|
||||
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)
|
||||
|
||||
if (Bluelib_STATIC)
|
||||
target_compile_definitions(Bluelib::${component} INTERFACE BLUELIB_STATIC=1)
|
||||
endif ()
|
||||
|
||||
set_target_properties(Bluelib::${component} PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${Bluelib_${component}_LIBRARY}")
|
||||
set(created_targets ${created_targets} ${component})
|
||||
endif ()
|
||||
endforeach (component)
|
||||
|
||||
foreach (component ${created_targets})
|
||||
if ("${component}" STREQUAL "Ds")
|
||||
if (NOT TARGET Bluelib::Core)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Ds' depends on 'Core', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Ds INTERFACE Bluelib::Core)
|
||||
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 ()
|
||||
|
||||
if (NOT TARGET Bluelib::Ds)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Ds', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Ds)
|
||||
endif ()
|
||||
|
||||
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 ()
|
||||
|
||||
if (NOT TARGET Bluelib::Ds)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Ds', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Ds)
|
||||
endif ()
|
||||
|
||||
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 ()
|
||||
|
||||
if (NOT TARGET Bluelib::Ds)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Ds', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET Bluelib::Term)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Ds Bluelib::Term)
|
||||
endif ()
|
||||
|
||||
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 ()
|
||||
|
||||
if (NOT TARGET Bluelib::Ds)
|
||||
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Ds', which was not specified in find_package()")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Ds)
|
||||
endif ()
|
||||
|
||||
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 ()
|
||||
|
||||
target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Ds)
|
||||
endif ()
|
||||
endforeach (component)
|
||||
endif()
|
||||
Reference in New Issue
Block a user