argtable / argtable3

A single-file, ANSI C, command-line parsing library that parses GNU-style command-line options.
http://www.argtable.org
Other
372 stars 65 forks source link

CMake not including header on static build #86

Closed tlf30 closed 8 months ago

tlf30 commented 8 months ago

Hello, I'm attempting to build a simple application, where I am statically linking against argtable3. I am using FetchContent to bring the library into the build.

FetchContent_Declare(argtable
        SOURCE_DIR "${PROJECT_SOURCE_DIR}/deps/argtable3-master"
)
FetchContent_MakeAvailable(argtable)

And then linking to it target_link_libraries(spyglass_core argtable3)

CMake correctly builds argtable3, but the argtable3.h is not exposed to the include path.

C:\PROGRA~1\JETBRA~1\CLION2~1.2\bin\mingw\bin\gcc.exe  -I"<censored>/src/include" -I"<censored>/deps/<censored>/include" -g -std=gnu90 -fdiagnostics-color=always -Wall -Wextra -Wpedantic -Wno-unused-parameter -MD -MT <censored>.c.obj -MF <censored>.c.obj.d -o <censored>.c.obj -c "<censored>.c"
<censored>.c:2:10: fatal error: argtable3.h: No such file or directory
    2 | #include <argtable3.h>
      |          ^~~~~~~~~~~~~

Sorry for the censorship, but the build command that CMake runs does not contain the include for argtable3.

I'm sure I am doing something wrong here, but this is working for my other dependencies. I am using the master copy of the branch, which has the #85 merged into it.

tlf30 commented 8 months ago

OK, I think I have found the issue (at least it works for me) In #85, the build interface was set to CMAKE_CURRENT_SOURCEDIR but the variable is actually CMAKE_CURRENT_SOURCE_DIR https://cmake.org/cmake/help/latest/variable/CMAKE_SOURCE_DIR.html

EDIT: https://github.com/argtable/argtable3/blob/55c4f6285e2f9b2f0cc96ae8212b7b943547c3dd/src/CMakeLists.txt#L81 should be fixed to say "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"