cmark-gfm icon indicating copy to clipboard operation
cmark-gfm copied to clipboard

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

Open xuboying opened this issue 4 months ago • 0 comments

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.

xuboying avatar Nov 11 '25 08:11 xuboying