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

Fix compile issue when used as submodule #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bruce87en
Copy link

Fix compile issue when used as submodule:
1.Modify BUILD_SHARED_LIBS to BUILD_LIBUSBP_SHARED_LIBS to avoid potential conflicts.
2.Modify the header file include path relative to the current CMakeLists.txt to avoid compilation errors caused by the top-level project not being libusbp.

@DavidEGrayson
Copy link
Member

DavidEGrayson commented Aug 6, 2024

Change 2 seems OK, but for change 1, the intention is to just use this standard CMake variable which automatically controls what type of library gets built, instead of defining our own:

https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

So I think the BUILD_SHARED_LIBS code should stay is it is, but you could elaborate on what specific problem it's causing for you

@NuLL3rr0r
Copy link

NuLL3rr0r commented Mar 4, 2025

Well, I personally am in fabor of @bruce87en approach, for example libusb-cmake have these option names, which is clean:

set(LIBUSB_BUILD_SHARED_LIBS            OFF             CACHE BOOL "Build shared libraries for libusb")
set(LIBUSB_BUILD_TESTING                ${BUILD_TESTS}  CACHE BOOL "Build testing for libusb")
set(LIBUSB_BUILD_EXAMPLES               OFF             CACHE BOOL "Build examples for libusb")
set(LIBUSB_INSTALL_TARGETS              OFF             CACHE BOOL "Disable installation targets for libusb")
set(LIBUSB_TARGETS_INCLUDE_USING_SYSTEM OFF             CACHE BOOL "Use system includes for libusb")
set(LIBUSB_ENABLE_LOGGING               ON              CACHE BOOL "Enable logging in libusb")
set(LIBUSB_ENABLE_DEBUG_LOGGING         OFF             CACHE BOOL "Enable debug logging in libusb")
set(LIBUSB_ENABLE_UDEV                  ON              CACHE BOOL "Enable udev support in libusb")

add_subdirectory(third-party/libusb-cmake)

Where as:

set(BUILD_SHARED_LIBS       OFF     CACHE   BOOL        "Build as shared library")
set(ENABLE_EXAMPLES         FALSE   CACHE   INTERNAL    "True if you want to build the examples.")
set(ENABLE_TESTS            ${BUILD_TESTS}    CACHE   INTERNAL    "True if you want to build the tests.")
set(LIBUSBP_LOG             FALSE   CACHE   INTERNAL    "Output log messages to stderr for debugging.")
set(VBOX_LINUX_ON_WINDOWS   FALSE   CACHE   INTERNAL    "Skip tests known to cause problems on a Linux VirtualBox guest on Windows.")
set(ENABLE_GCOV             FALSE   CACHE   INTERNAL    "Compile with special options needed for gcov.")

add_subdirectory(third-party/libusbp)

unset(BUILD_SHARED_LIBS)
unset(ENABLE_EXAMPLES)
unset(ENABLE_TESTS)
#unset(LIBUSBP_LOG)
unset(VBOX_LINUX_ON_WINDOWS)
unset(ENABLE_GCOV)

The reason is we want to build some things statically and some things dynamically. His approach which is used by many cmake-based projects is more flexible, because does not impose an unset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants