From 1573db38609db7a33030d65227cbf3cf8e065189 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Mon, 27 Mar 2023 19:46:29 +0200 Subject: [PATCH] libfxlink: install the library --- CMakeLists.txt | 6 +++ libfxlink/cmake/FindLibFxlink.cmake | 58 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 libfxlink/cmake/FindLibFxlink.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4477ce0..fa46dd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,5 +97,11 @@ install(FILES "${BIN}/fxg1a" TYPE BIN) # fxconv install(PROGRAMS fxconv/fxconv-main.py TYPE BIN RENAME fxconv) install(FILES fxconv/fxconv.py TYPE BIN) +# libfxlink +install(FILES "${BIN}/include/fxlink/config.h" DESTINATION include/fxlink/) +install(DIRECTORY libfxlink/include/ DESTINATION include + FILES_MATCHING PATTERN "*.h") +install(DIRECTORY libfxlink/cmake/ DESTINATION lib/cmake) +install(TARGETS libfxlink DESTINATION lib) # fxlink install(TARGETS fxlink) diff --git a/libfxlink/cmake/FindLibFxlink.cmake b/libfxlink/cmake/FindLibFxlink.cmake new file mode 100644 index 0000000..e624fd2 --- /dev/null +++ b/libfxlink/cmake/FindLibFxlink.cmake @@ -0,0 +1,58 @@ +# Locate the library file and includes + +message("test: $ENV{HOME}/.local/lib $ENV{FXSDK_PATH}/lib") +find_library( + LIBFXLINK_PATH "fxlink" + HINTS "$ENV{HOME}/.local/lib" "$ENV{FXSDK_PATH}/lib" +) +if(LIBFXLINK_PATH STREQUAL "LIBFXLINK_PATH-NOTFOUND") + message(SEND_ERROR + "Could not find libfxlink.a!\n" + "You can specify the install path with the environment variable " + "FXSDK_PATH, such as FXSDK_PATH=$HOME/.local") +else() + get_filename_component(LIBFXLINK_PATH "${LIBFXLINK_PATH}/../.." ABSOLUTE) + set(LIBFXLINK_LIB "${LIBFXLINK_PATH}/lib/libfxlink.a") + set(LIBFXLINK_INCLUDE "${LIBFXLINK_PATH}/include") + + message("(libfxlink) Found libfxlink at: ${LIBFXLINK_LIB}") + message("(libfxlink) Will take includes from: ${LIBFXLINK_INCLUDE}") +endif() + +# Find library version + +if(NOT EXISTS "${LIBFXLINK_INCLUDE}/fxlink/config.h") + message(SEND_ERROR + "No exists at ${LIBFXLINK_INCLUDE}/fxlink/config.h\n" + "Is libfxlink installed alongside the headers?") +endif() + +execute_process( + COMMAND sed "s/#define FXLINK_VERSION \"\\([^\"]\\{1,\\}\\)\"/\\1/p; d" + "${LIBFXLINK_INCLUDE}/fxlink/config.h" + OUTPUT_VARIABLE LIBFXLINK_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) +message("(libfxlink) Library version found in header: ${LIBFXLINK_VERSION}") + +# Handle find_package() arguments and find dependencies + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LibFxlink + REQUIRED_VARS LIBFXLINK_LIB LIBFXLINK_INCLUDE + VERSION_VAR LIBFXLINK_VERSION) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(libusb REQUIRED libusb-1.0 IMPORTED_TARGET) + +# Generate targets + +if(LibFxlink_FOUND) + if(NOT TARGET LibFxlink::LibFxlink) + add_library(LibFxlink::LibFxlink UNKNOWN IMPORTED) + endif() + + set_target_properties(LibFxlink::LibFxlink PROPERTIES + IMPORTED_LOCATION "${LIBFXLINK_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBFXLINK_INCLUDE}") + target_link_libraries(LibFxlink::LibFxlink INTERFACE PkgConfig::libusb) +endif()