Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD/CMake include location fixes ftdi1 build problem. #925

Conversation

cederom
Copy link
Contributor

@cederom cederom commented Apr 9, 2022

This commit appends /usr/local/include include location on FreeBSD.
This fixes missing libftdi1/ftdi.h build error.

Fixed build problem:

% rm -rf build; cmake -B build; cmake --build build
-- The C compiler identification is Clang 11.0.1
-- The CXX compiler identification is Clang 11.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/local/bin/git (found version "2.35.1")
-- Found FLEX: /usr/bin/flex (found version "2.6.4")
-- Found BISON: /usr/local/bin/bison (found version "3.8.2")
-- Looking for libelf.h
-- Looking for libelf.h - found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - not found
-- Looking for usb.h
-- Looking for usb.h - found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - not found
-- Looking for libusb.h
-- Looking for libusb.h - found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - not found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - not found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - not found
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DO HAVE    libftdi (but prefer to use libftdi1)
-- DO HAVE    libftdi1
-- DISABLED   doc
-- DISABLED   parport
-- DISABLED   linuxgpio
-- DISABLED   linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /XXX/avrdude.git/build
[  1%] [FLEX][Parser] Building scanner with flex 2.6.4
[  3%] [BISON][Parser] Building parser with bison 3.8.2
[  4%] Building C object src/CMakeFiles/libavrdude.dir/arduino.c.o
[  6%] Building C object src/CMakeFiles/libavrdude.dir/avr.c.o
[  8%] Building C object src/CMakeFiles/libavrdude.dir/avr910.c.o
[  9%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
In file included from /XXX/avrdude.git/src/avrftdi.c:41:
/XXX/avrdude.git/src/avrftdi_private.h:12:11: fatal error: 'libftdi1/ftdi.h' file not found
          ^~~~~~~~~~~~~~~~~
1 error generated.
gmake[2]: *** [src/CMakeFiles/libavrdude.dir/build.make:129: src/CMakeFiles/libavrdude.dir/avrftdi.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:100: src/CMakeFiles/libavrdude.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

Signed-off-by: Tomasz 'CeDeROM' CEDRO tomek@cedro.info

This commit appends `/usr/local/include` include location on FreeBSD.
This fixes missing `libftdi1/ftdi.h` build error.

Fixed build problem:
```
% rm -rf build; cmake -B build; cmake --build build
-- The C compiler identification is Clang 11.0.1
-- The CXX compiler identification is Clang 11.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/local/bin/git (found version "2.35.1")
-- Found FLEX: /usr/bin/flex (found version "2.6.4")
-- Found BISON: /usr/local/bin/bison (found version "3.8.2")
-- Looking for libelf.h
-- Looking for libelf.h - found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - not found
-- Looking for usb.h
-- Looking for usb.h - found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - not found
-- Looking for libusb.h
-- Looking for libusb.h - found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - not found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - not found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - not found
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DO HAVE    libftdi (but prefer to use libftdi1)
-- DO HAVE    libftdi1
-- DISABLED   doc
-- DISABLED   parport
-- DISABLED   linuxgpio
-- DISABLED   linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /XXX/avrdude.git/build
[  1%] [FLEX][Parser] Building scanner with flex 2.6.4
[  3%] [BISON][Parser] Building parser with bison 3.8.2
[  4%] Building C object src/CMakeFiles/libavrdude.dir/arduino.c.o
[  6%] Building C object src/CMakeFiles/libavrdude.dir/avr.c.o
[  8%] Building C object src/CMakeFiles/libavrdude.dir/avr910.c.o
[  9%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
In file included from /XXX/avrdude.git/src/avrftdi.c:41:
/XXX/avrdude.git/src/avrftdi_private.h:12:11: fatal error: 'libftdi1/ftdi.h' file not found
          ^~~~~~~~~~~~~~~~~
1 error generated.
gmake[2]: *** [src/CMakeFiles/libavrdude.dir/build.make:129: src/CMakeFiles/libavrdude.dir/avrftdi.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:100: src/CMakeFiles/libavrdude.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2
```

Signed-off-by: Tomasz 'CeDeROM' CEDRO <tomek@cedro.info>
@dl8dtl
Copy link
Contributor

dl8dtl commented Apr 9, 2022

Well, I'n not sure it's a good idea to put various possible system-dependant locations straight into the CMake infrastructure.
Please have a look at the build.sh script in the top-level directory: that would be my preferred way to offer OS customization for Unix-like OSes.

@cederom
Copy link
Contributor Author

cederom commented Apr 9, 2022

Negative @dl8dtl. We should stick to generic build. Because generic build does not work out-of-the-box, the FreeBSD Port needs to add local patches in order to build. I saw your script, it modifies the CFLAGS. This should be done by cmake so we have out of the box build in a generic way :-)

If anyone knows better way to add /usr/local/include in cmake please advise :-)

This location can be safely added in a non-system-dependant way. I am not sure why /usr/local/include/ is not searched by default (as it should).

@cederom
Copy link
Contributor Author

cederom commented Apr 9, 2022

Another generic non-os specific way could be:

find_path(FTDI1_INCLUDE_PATH "libftdi1/ftdi.h")
include_directories(AFTER SYSTEM ${FTDI1_INCLUDE_PATH})

Update: Above check should be done for all libraries. Adding /usr/local/include fixes all include search path problems on FreeBSD.

@cederom
Copy link
Contributor Author

cederom commented Apr 9, 2022

But the most proper way would be including for instance /usr/local/lib/cmake/libftdi1/LibFTDI1Config.cmake and other libraries cmake packages as they contain all necessary variables ;-)

@cederom
Copy link
Contributor Author

cederom commented Apr 10, 2022

@hselasky could you please take a look and advise how cmake could add /usr/local/include location on FreeBSD? I have used solution visible in other projects but there may be a better way with current cmake design in the project? :-)

@dl8dtl
Copy link
Contributor

dl8dtl commented Apr 10, 2022

I still don't think it's a good idea to fill up AVRDUDE's CMake files with OS-specific stuff.
Look at build.sh, MacOS already requires two (or more) different options.
A lot of FreeBSD ports tweak CFLAGS (and LDFLAGS) in their configure environment to include /usr/local pathes.
If at all, it were the job of FreeBSD's CMake build to always include ${PREFIX} into the search order – after all, CMake there does know which environment it is being built for.

@cederom
Copy link
Contributor Author

cederom commented Apr 10, 2022

You know this is the CMAKE task to setup build enviroment so user just type make in order to build with no additional tweaking environment changes and scripts?

Using library specific cmake packages would be the most elegant way but that would require big rewrite.

My proposition is the least invasive way. The same can be done for Darwin.

The goal of using cmake is to run cmake then make and have result ready.

@dl8dtl
Copy link
Contributor

dl8dtl commented Apr 10, 2022

You know this is the CMAKE task to setup build enviroment

Well, it's FreeBSD that has decided to go to /usr/local by default, so it's FreeBSD's job to handle that. I think tweaking FreeBSD's CMake to do this automatically were indeed not a bad idea, but dumping that job over to each individual software is spamming individual projects with OS-specific decisions.

@cederom
Copy link
Contributor Author

cederom commented Apr 10, 2022

Again, if current cmake configuratrion had included the library packages as they should there would be no problem. We need to tell cmake what packages are used and what are their parameters. This is not the OS task but the author of the cmake file specific to a program that it builds. User is just supposed to run cmake then make and get the result ready.

Simply adding the includes path solves the problem quickly, efficiently, and does not need rewrite of current cmake files.. also it does not force users to set up any environment variables, run additional scripts, or any other voodoo that is Linux mindset approach. This is FreeBSD "specific" solution because location is for sure existing here, it may not exist on other OS and that could cause problems.

Please also note that cmake contains FreeBSD specific LibUSB 0.1 / 1.0 related detection because we have our own implementation here that is compatible with both LibUSB 0.1 and 1.0 but have different file locations. cmake configuration is the correct place to perform this kind of build setup.

Take a look at /usr/local/lib/cmake/libftdi1/LibFTDI1Config.cmake and note it contains all of the information that we need. On various OS it will contains information specific to that OS installation. Using these modules would have solved the problem completely.

#                                               -*- cmake -*-
#
#  LibFTDI1Config.cmake(.in)
#
#  Copyright (C) 2013 Intra2net AG and the libftdi developers
#
#  This file is part of LibFTDI.
#
#  LibFTDI is free software; you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License
#  version 2.1 as published by the Free Software Foundation;
#

# Use the following variables to compile and link against LibFTDI:
#  LIBFTDI_FOUND              - True if LibFTDI was found on your system
#  LIBFTDI_USE_FILE           - The file making LibFTDI usable
#  LIBFTDI_DEFINITIONS        - Definitions needed to build with LibFTDI
#  LIBFTDI_INCLUDE_DIRS       - Directory where ftdi.h can be found
#  LIBFTDI_INCLUDE_DIRS       - List of directories of LibFTDI and it's dependencies
#  LIBFTDI_LIBRARY            - LibFTDI library location
#  LIBFTDI_LIBRARIES          - List of libraries to link against LibFTDI library
#  LIBFTDIPP_LIBRARY          - LibFTDI C++ wrapper library location
#  LIBFTDIPP_LIBRARIES        - List of libraries to link against LibFTDI C++ wrapper
#  LIBFTDI_LIBRARY_DIRS       - List of directories containing LibFTDI' libraries
#  LIBFTDI_ROOT_DIR           - The base directory of LibFTDI
#  LIBFTDI_VERSION_STRING     - A human-readable string containing the version
#  LIBFTDI_VERSION_MAJOR      - The major version of LibFTDI
#  LIBFTDI_VERSION_MINOR      - The minor version of LibFTDI
#  LIBFTDI_VERSION_PATCH      - The patch version of LibFTDI
#  LIBFTDI_PYTHON_MODULE_PATH - Path to the python module

set ( LIBFTDI_FOUND 1 )
set ( LIBFTDI_USE_FILE     "/usr/local/lib/cmake/libftdi1/UseLibFTDI1.cmake" )

set ( LIBFTDI_DEFINITIONS  "" )
set ( LIBFTDI_INCLUDE_DIR  "/usr/local/include/libftdi1" )
set ( LIBFTDI_INCLUDE_DIRS "/usr/local/include/libftdi1" )
set ( LIBFTDI_LIBRARY      "ftdi1" )
set ( LIBFTDI_LIBRARIES    "ftdi1;/usr/lib/libusb.so" )
set ( LIBFTDI_STATIC_LIBRARY      "ftdi1.a" )
set ( LIBFTDI_STATIC_LIBRARIES    "ftdi1.a;/usr/lib/libusb.so" )
set ( LIBFTDIPP_LIBRARY    "ftdipp1" )
set ( LIBFTDIPP_LIBRARIES  "ftdipp1;/usr/lib/libusb.so" )
set ( LIBFTDI_LIBRARY_DIRS "/usr/local/lib" )
set ( LIBFTDI_ROOT_DIR     "/usr/local" )

set ( LIBFTDI_VERSION_STRING "1.5" )
set ( LIBFTDI_VERSION_MAJOR  "1" )
set ( LIBFTDI_VERSION_MINOR  "5" )
set ( LIBFTDI_VERSION_PATCH  "" )

set ( LIBFTDI_PYTHON_MODULE_PATH "/usr/local/lib/python3.8/site-packages" )

@hselasky
Copy link

hselasky commented Apr 11, 2022

@cederom : Could you run a dummy target, "env", to see what environments are already set, or get the full enviroment for cmake. I'm pretty sure FreeBSD's /usr/ports/Mk/cmake is passing on /usr/local/include, but maybe it is lost somehow.

@cederom
Copy link
Contributor Author

cederom commented Apr 21, 2022

Well, I just wanted to have it built out of the box on a local git clone outside the ports tree, just as any other cmake based software.. but I can also use provided shell script no problem :-)

@mcuee
Copy link
Collaborator

mcuee commented May 15, 2022

@cederom : Could you run a dummy target, "env", to see what environments are already set, or get the full enviroment for cmake. I'm pretty sure FreeBSD's /usr/ports/Mk/cmake is passing on /usr/local/include, but maybe it is lost somehow.

@hselasky Just wondering how to do that? I can help here with my FreeBSD VM.

@mcuee
Copy link
Collaborator

mcuee commented May 15, 2022

@cederom I do not think this patch is needed at all. It is similar to the macOS M1 case as mentioned here.
#939

You just need to carry out minor modification to build.sh for FreeBSD.

mcuee@freebsdx64vm:~/build/avrdude/build $ cmake -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/lib -D CMAKE_BUILD_TYPE=RelWithDeb
Info ..
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DON'T HAVE libftdi
-- DO HAVE    libftdi1
-- DISABLED   doc
-- DISABLED   parport
-- DISABLED   linuxgpio
-- DISABLED   linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mcuee/build/avrdude/build
mcuee@freebsdx64vm:~/build/avrdude/build $ make
Consolidate compiler generated dependencies of target libavrdude
[  1%] Building C object src/CMakeFiles/libavrdude.dir/arduino.c.o
[  3%] Building C object src/CMakeFiles/libavrdude.dir/avr.c.o
[  4%] Building C object src/CMakeFiles/libavrdude.dir/avr910.c.o
[  6%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi.c.o
/home/mcuee/build/avrdude/src/avrftdi.c:727:4: warning: 'ftdi_usb_purge_buffers' is deprecated [-Wdeprecated-declarations]
        E(ftdi_usb_purge_buffers(pdata->ftdic), pdata->ftdic);
          ^
/usr/local/include/libftdi1/ftdi.h:566:9: note: 'ftdi_usb_purge_buffers' has been explicitly marked deprecated here
    int DEPRECATED(ftdi_usb_purge_buffers(struct ftdi_context *ftdi));
        ^
/usr/local/include/libftdi1/ftdi.h:247:42: note: expanded from macro 'DEPRECATED'
#define DEPRECATED(func) __attribute__ ((deprecated)) func
                                         ^
1 warning generated.
[  8%] Building C object src/CMakeFiles/libavrdude.dir/avrftdi_tpi.c.o
[  9%] Building C object src/CMakeFiles/libavrdude.dir/avrpart.c.o
[ 11%] Building C object src/CMakeFiles/libavrdude.dir/bitbang.c.o
[ 13%] Building C object src/CMakeFiles/libavrdude.dir/buspirate.c.o
[ 14%] Building C object src/CMakeFiles/libavrdude.dir/butterfly.c.o
[ 16%] Building C object src/CMakeFiles/libavrdude.dir/config.c.o
[ 18%] Building C object src/CMakeFiles/libavrdude.dir/confwin.c.o
[ 19%] Building C object src/CMakeFiles/libavrdude.dir/crc16.c.o
[ 21%] Building C object src/CMakeFiles/libavrdude.dir/dfu.c.o
[ 22%] Building C object src/CMakeFiles/libavrdude.dir/fileio.c.o
[ 24%] Building C object src/CMakeFiles/libavrdude.dir/flip1.c.o
[ 26%] Building C object src/CMakeFiles/libavrdude.dir/flip2.c.o
[ 27%] Building C object src/CMakeFiles/libavrdude.dir/ft245r.c.o
[ 29%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkI.c.o
[ 31%] Building C object src/CMakeFiles/libavrdude.dir/jtagmkII.c.o
[ 32%] Building C object src/CMakeFiles/libavrdude.dir/jtag3.c.o
[ 34%] Building C object src/CMakeFiles/libavrdude.dir/linuxgpio.c.o
[ 36%] Building C object src/CMakeFiles/libavrdude.dir/linuxspi.c.o
[ 37%] Building C object src/CMakeFiles/libavrdude.dir/lists.c.o
[ 39%] Building C object src/CMakeFiles/libavrdude.dir/micronucleus.c.o
[ 40%] Building C object src/CMakeFiles/libavrdude.dir/par.c.o
[ 42%] Building C object src/CMakeFiles/libavrdude.dir/pgm.c.o
[ 44%] Building C object src/CMakeFiles/libavrdude.dir/pgm_type.c.o
[ 45%] Building C object src/CMakeFiles/libavrdude.dir/pickit2.c.o
[ 47%] Building C object src/CMakeFiles/libavrdude.dir/pindefs.c.o
[ 49%] Building C object src/CMakeFiles/libavrdude.dir/ppi.c.o
[ 50%] Building C object src/CMakeFiles/libavrdude.dir/ppiwin.c.o
[ 52%] Building C object src/CMakeFiles/libavrdude.dir/serbb_posix.c.o
[ 54%] Building C object src/CMakeFiles/libavrdude.dir/serbb_win32.c.o
[ 55%] Building C object src/CMakeFiles/libavrdude.dir/ser_avrdoper.c.o
[ 57%] Building C object src/CMakeFiles/libavrdude.dir/ser_posix.c.o
[ 59%] Building C object src/CMakeFiles/libavrdude.dir/ser_win32.c.o
[ 60%] Building C object src/CMakeFiles/libavrdude.dir/serialupdi.c.o
[ 62%] Building C object src/CMakeFiles/libavrdude.dir/stk500.c.o
[ 63%] Building C object src/CMakeFiles/libavrdude.dir/stk500v2.c.o
[ 65%] Building C object src/CMakeFiles/libavrdude.dir/stk500generic.c.o
[ 67%] Building C object src/CMakeFiles/libavrdude.dir/teensy.c.o
[ 68%] Building C object src/CMakeFiles/libavrdude.dir/updi_link.c.o
[ 70%] Building C object src/CMakeFiles/libavrdude.dir/updi_nvm.c.o
[ 72%] Building C object src/CMakeFiles/libavrdude.dir/updi_readwrite.c.o
[ 73%] Building C object src/CMakeFiles/libavrdude.dir/updi_state.c.o
[ 75%] Building C object src/CMakeFiles/libavrdude.dir/usbasp.c.o
[ 77%] Building C object src/CMakeFiles/libavrdude.dir/usb_hidapi.c.o
[ 78%] Building C object src/CMakeFiles/libavrdude.dir/usb_libusb.c.o
[ 80%] Building C object src/CMakeFiles/libavrdude.dir/usbtiny.c.o
[ 81%] Building C object src/CMakeFiles/libavrdude.dir/update.c.o
[ 83%] Building C object src/CMakeFiles/libavrdude.dir/wiring.c.o
[ 85%] Building C object src/CMakeFiles/libavrdude.dir/xbee.c.o
[ 86%] Building C object src/CMakeFiles/libavrdude.dir/__/lexer.c.o
[ 88%] Building C object src/CMakeFiles/libavrdude.dir/__/config_gram.c.o
[ 90%] Linking C static library libavrdude.a
[ 93%] Built target libavrdude
[ 95%] Building C object src/CMakeFiles/avrdude.dir/main.c.o
[ 96%] Building C object src/CMakeFiles/avrdude.dir/term.c.o
[ 98%] Building C object src/CMakeFiles/avrdude.dir/whereami.c.o
[100%] Linking C executable avrdude
[100%] Built target avrdude

@mcuee
Copy link
Collaborator

mcuee commented May 15, 2022

@cederom You can however create a pull request to fix build.sh for FreeBSD, just like #950.

@cederom
Copy link
Contributor Author

cederom commented May 15, 2022

Okay, there is a script to build on FreeBSD. I wanted build with cmake to work out of the box. If this is not the part of this project design then we can just close that PR :-) Thank you for your time everyone :-)

@cederom cederom closed this May 15, 2022
@mcuee
Copy link
Collaborator

mcuee commented May 15, 2022

@cederom FreeBSD build instruction is documented in the Wiki.
https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-FreeBSD

But yes it may be good to debug the CMake system as suggested by HPS to see why it is not as easy as Linux (by right /usr/local should be picked up just like /usr).
Ref: https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-Linux

@cederom
Copy link
Contributor Author

cederom commented May 15, 2022

  • CMake needs to have all paths provided in CMakeLists.txt.
  • External cmake package for LibFTDI1 is not included in top level CMake configuration (see explanation previous comments).
  • On Linux this LibFTDI1 package just happens to be in the place already defined and used by other packages. It is not the case for BSD/macOS.
  • Currently the paths are provided over cmake args / environment variables to the compiler and needs to be typed as cmake parameter. This could be included in CMakeLists.txt so build "just works" out of the box on various platforms. That was my intent.
  • What HPS suggested is FreeBSD Port infrastructure build verification. This is working fine as we have package build out of the box in the Port Tree (that requires creating a dedicated port and Makefile for build automation) and package is available via binary packages sets (pkg install avrdude).
  • Proposed approach would be helpful for people that want to clone and build the avrdude in order to debug / fix it. Out of the box. With no additional scripts, typing, wikis.
  • I can understand that CMake configuration script may be designed in a way to be kept as simple as possible and all additional stuff needs to be provided to cmake invocation as shell parameter / environment variable.

@mcuee
Copy link
Collaborator

mcuee commented May 15, 2022

Probably cmake can use pkg-config (FreeBSD: pkgconf) to detect the packages. It should work for Linux, macOS and FreeBSD, and also Windows MSYS2. I am not so familiar with CMake though.

@hselasky
Copy link

Some help here:
https://stackoverflow.com/questions/45396923/how-do-i-tell-cmake-where-to-find-libusb

I think FreeBSD only needs "libusb" and not "libusb-1.0", but maybe both will work.

--HPS

@mcuee
Copy link
Collaborator

mcuee commented May 15, 2022

@hselasky The issue here is not libusb or libusb-1.0 (where FreeBSD has a different implemtnation from other OS, but still under /usr), rather the issue is libftdi1 (under /usr/local).

pkg-config will work for both libusb-1.0 and libftdi1, and for libusb-0.1 and libftdi (old 0.x version) as well.

mcuee@freebsdx64vm:~ $ pkg-config -cflags libftdi1
-I/usr/local/include/libftdi1 
mcuee@freebsdx64vm:~ $ pkg-config -libs libftdi1
-L/usr/local/lib -lftdi1 -lusb 

mcuee@freebsdx64vm:~ $ pkg-config -cflags libftdi
-I/usr/local/include 
mcuee@freebsdx64vm:~ $ pkg-config -libs libftdi
-L/usr/local/lib -lftdi -lusb 

mcuee@freebsdx64vm:~ $ pkg-config -cflags libusb-1.0

mcuee@freebsdx64vm:~ $ pkg-config -libs libusb-1.0
-lusb 

mcuee@freebsdx64vm:~ $ pkg-config -cflags libusb-0.1

mcuee@freebsdx64vm:~ $ pkg-config -libs libusb-0.1
-lusb 


@hselasky
Copy link

I see :-)

@mariusgreuel
Copy link
Contributor

Probably cmake can use pkg-config (FreeBSD: pkgconf) to detect the packages. It should work for Linux, macOS and FreeBSD, and also Windows MSYS2.

We need plain Windows too, so I would rather stick to built-in cross-platform functions such as find_library.

@mcuee
Copy link
Collaborator

mcuee commented May 16, 2022

Probably cmake can use pkg-config (FreeBSD: pkgconf) to detect the packages. It should work for Linux, macOS and FreeBSD, and also Windows MSYS2.

We need plain Windows too, so I would rather stick to built-in cross-platform functions such as find_library.

Is it possible to use pkg-config first and then fall-back to "find_library"?

From what I see, many problem related to CMake seems to be related to the in-ability of "find_library". Usually the fall_back is for the user to specify the location of the header file and the library.

Maybe arvdude can help a bit so that CMake can work out of the box for non-MSVC users.

@mcuee mcuee mentioned this pull request May 17, 2022
@mcuee mcuee added the invalid This doesn't seem right label Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants