diff --git a/cmake/FindBluelib.cmake b/cmake/FindBluelib.cmake new file mode 100644 index 0000000..72780e2 --- /dev/null +++ b/cmake/FindBluelib.cmake @@ -0,0 +1,113 @@ +#[=======================================================================[.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 Object Term Cmd) +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) + 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) + + set_target_properties(Bluelib::${component} PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${Bluelib_${component}_LIBRARY}") + endif () + endforeach (component) +endif()