Skip to content

CMakeLists.txt missing PUBLIC include in add_library, cause missing header file compile error #378

@xuboying

Description

@xuboying

version 587a12b

It seems the addlibrary in project cmake file is missing the PUBLIC include part, causing target_link_libraries could not properly resolve the header files properly.

Example target_link_libraries (good practice of add any libraries):

target_link_libraries(
    myapp PRIVATE
    libcmark-gfm_static
    libcmark-gfm-extensions_static
)

Error triggered without patch:

fatal error: 'cmark-gfm.h' file not found

Fix:

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 84dd2a0..7a92938 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -120,6 +120,8 @@ endif()

 if (CMARK_STATIC)
   add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES})
+  target_include_directories(${STATICLIBRARY} PUBLIC ${CMAKE_CURRENT_LIST_DIR})  # for cmark-gfm.h file
+  target_include_directories(${STATICLIBRARY} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) # generate header file used by framework itself
   set_target_properties(${STATICLIBRARY} PROPERTIES
     COMPILE_FLAGS -DCMARK_GFM_STATIC_DEFINE
     POSITION_INDEPENDENT_CODE ON)

The patch fixes static linking issue, not sure if dynamic linkink(not used in my project) has same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions