Ensure Iconv is found when provided via CFLAGS/LDFLAGS #430

Merged
Youw merged 4 commits from find_iconv into master 2022-06-21 17:30:46 -05:00
Youw commented 2022-06-18 07:59:40 -05:00 (Migrated from github.com)
  • by default find_file/find_library doesn't respect CFLAGS/LDFLAGS, and FindIconv fails to find Iconv;
  • by explicitly trying to link against -liconv - we're checking if library is available in such way;
  • additionally: if Iconv is detected as BUILT_IN, no need to explicitly depend on Iconv::Iconv;

Fixes: #429

- by default find_file/find_library doesn't respect CFLAGS/LDFLAGS, and FindIconv fails to find Iconv; - by explicitly trying to link against `-liconv` - we're checking if library is available in such way; - additionally: if Iconv is detected as BUILT_IN, no need to explicitly depend on `Iconv::Iconv`; Fixes: #429
Youw commented 2022-06-18 08:01:55 -05:00 (Migrated from github.com)

Right now I don't have the environment to check this properly (except what is setup on CI).

@neheb can you check this as part of the openwrt build?

Right now I don't have the environment to check this properly (except what is setup on CI). @neheb can you check this as part of the openwrt build?
neheb commented 2022-06-18 18:44:39 -05:00 (Migrated from github.com)

As soon as I get home.

As soon as I get home.
neheb commented 2022-06-19 23:14:02 -05:00 (Migrated from github.com)

nope:

-- The C compiler identification is GNU 12.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/mangix/devstuff/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.1.0_musl/bin/mips-openwrt-linux-musl-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- hidapi: v0.12.0
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found PkgConfig: /home/mangix/devstuff/openwrt/staging_dir/host/bin/pkg-config (found version "1.8.0")
-- Checking for module 'libudev'
--   Found libudev, version 243
-- Checking for module 'libusb-1.0>=1.0.9'
--   Found libusb-1.0, version 1.0.24
-- Performing Test Iconv_IS_BUILT_IN
-- Performing Test Iconv_IS_BUILT_IN - Failed
-- Could NOT find Iconv (missing: Iconv_LIBRARY)
-- Could NOT find Iconv (missing: Iconv_LIBRARY)
CMake Error at libusb/CMakeLists.txt:41 (message):
  Iconv is not found, make sure your build environment is right


-- Configuring incomplete, errors occurred!
See also "/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/hidapi-hidapi-0.12.0/CMakeFiles/CMakeOutput.log".
See also "/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/hidapi-hidapi-0.12.0/CMakeFiles/CMakeError.log".
nope: ``` -- The C compiler identification is GNU 12.1.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /home/mangix/devstuff/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.1.0_musl/bin/mips-openwrt-linux-musl-gcc - skipped -- Detecting C compile features -- Detecting C compile features - done -- hidapi: v0.12.0 -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Found PkgConfig: /home/mangix/devstuff/openwrt/staging_dir/host/bin/pkg-config (found version "1.8.0") -- Checking for module 'libudev' -- Found libudev, version 243 -- Checking for module 'libusb-1.0>=1.0.9' -- Found libusb-1.0, version 1.0.24 -- Performing Test Iconv_IS_BUILT_IN -- Performing Test Iconv_IS_BUILT_IN - Failed -- Could NOT find Iconv (missing: Iconv_LIBRARY) -- Could NOT find Iconv (missing: Iconv_LIBRARY) CMake Error at libusb/CMakeLists.txt:41 (message): Iconv is not found, make sure your build environment is right -- Configuring incomplete, errors occurred! See also "/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/hidapi-hidapi-0.12.0/CMakeFiles/CMakeOutput.log". See also "/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/hidapi-hidapi-0.12.0/CMakeFiles/CMakeError.log". ```
Youw commented 2022-06-20 07:31:48 -05:00 (Migrated from github.com)

Updated. This time I was able to test it partially.

Updated. This time I was able to test it _partially_.
neheb commented 2022-06-20 14:39:55 -05:00 (Migrated from github.com)

Seems to have done it. A lot of work as compared to

dependency('iconv')

though.

Seems to have done it. A lot of work as compared to ``` dependency('iconv') ``` though.
Youw commented 2022-06-20 14:58:53 -05:00 (Migrated from github.com)

Not a lot of work, compared to uncompleted #426 :)

Besides, I'll ask CMake community, if this can be improved by CMake itself, even though openwrt CMake support is too incomplete as of yet.


Thanks for testing it.

Not a lot of work, compared to _uncompleted_ #426 :) Besides, I'll ask CMake community, if this can be improved by CMake itself, even though openwrt CMake support is too incomplete as of yet. --- Thanks for testing it.
Youw (Migrated from github.com) reviewed 2022-06-20 15:02:21 -05:00
@ -22,11 +22,53 @@ target_link_libraries(hidapi_libusb PRIVATE Threads::Threads)
if(HIDAPI_NO_ICONV)
Youw (Migrated from github.com) commented 2022-06-20 15:01:53 -05:00
                    int main() {
                        char *a, *b;
                        size_t i, j;
                        iconv_t ic;
                        ic = iconv_open(\"to\", \"from\");
                        iconv(ic, &a, &i, &b, &j);
                        iconv_close(ic);
                    }
```suggestion int main() { char *a, *b; size_t i, j; iconv_t ic; ic = iconv_open(\"to\", \"from\"); iconv(ic, &a, &i, &b, &j); iconv_close(ic); } ```
neheb commented 2022-06-20 15:03:13 -05:00 (Migrated from github.com)

I do agree CMake's Find_Iconv is not that great, Fixing it upstream would be good.

The OpenWrt comment is interesting. I don't really know what the "proper" way of handling cross compilation is like this. Although cmake.mk probably predates whatever "proper" is.

I do agree CMake's Find_Iconv is not that great, Fixing it upstream would be good. The OpenWrt comment is interesting. I don't really know what the "proper" way of handling cross compilation is like this. Although cmake.mk probably predates whatever "proper" is.
Youw commented 2022-06-20 15:21:56 -05:00 (Migrated from github.com)

I don't really know what the "proper" way of handling cross compilation is like this.

Let me share with you a few links, as a general reference:

  • The best way to cross-compile with CMake is to prepare a CMake toolchain file. Here is the official documentation: https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html
    So instead of specifying so many CMake arguments and environment varibales - a single additional CMake argument should be passed: -DCMAKE_TOOLCHAIN_FILE=<toolchain for cross-compilation>;
  • a very good example of CMake toolchain file is the one provided by Android NDK. The one I used recently is located at: ndk/22.1.7171670/build/cmake/android.toolchain.cmake;
  • some while ago I've been using Yocto builds for one of the development boards; Yocto has mature CMake support - that I remember, even though cannot really share a specific link to check out;

BTW:

the one provided by Android

I'm successfully using with HIDAPI (and not only) in several of my projects.

> I don't really know what the "proper" way of handling cross compilation is like this. Let me share with you a few links, as a general reference: - The best way to cross-compile with CMake is to prepare a CMake _toolchain_ file. Here is the official documentation: https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html So instead of specifying so many CMake arguments and environment varibales - a single additional CMake argument should be passed: `-DCMAKE_TOOLCHAIN_FILE=<toolchain for cross-compilation>`; - a very good example of CMake _toolchain_ file is the one provided by Android [NDK](https://developer.android.com/ndk/downloads). The one I used recently is located at: `ndk/22.1.7171670/build/cmake/android.toolchain.cmake`; - some while ago I've been using Yocto builds for one of the development boards; Yocto has mature CMake support - that I remember, even though cannot really share a specific link to check out; --- BTW: > the one provided by Android I'm successfully using with HIDAPI (and not only) in several of my projects.
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi!430
No description provided.