cmark

My personal build of CMark ✏️

Commit
b6c73d8b5c23000b1c548a01db4019e0a3a53c02
Parent
57a8094934ea2b73acce831fe2ffb030496020f7
Author
Saleem Abdulrasool <compnerd@compnerd.org>
Date

build: use target properties for include paths

This configures the target to setup the include paths publicly for the library targets in the build interface. This enables uses of the targets in the build tree without having to specify the include directories. This is particularly useful for use in the export targets, but also simplifies the rules for the API tests. The install interface does not need the include directories as `cmark.h` is installed into `include` which is a default include path.

Diffstat

2 files changed, 8 insertions, 4 deletions

Status File Name N° Changes Insertions Deletions
Modified api_test/CMakeLists.txt 4 0 4
Modified src/CMakeLists.txt 8 8 0
diff --git a/api_test/CMakeLists.txt b/api_test/CMakeLists.txt
@@ -4,10 +4,6 @@ add_executable(api_test
   harness.h
   main.c
 )
-include_directories(
-  ${PROJECT_SOURCE_DIR}/src
-  ${PROJECT_BINARY_DIR}/src
-)
 if(CMARK_SHARED)
   target_link_libraries(api_test libcmark)
 else()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -72,6 +72,10 @@ if (CMARK_SHARED)
     # Include minor version and patch level in soname for now.
     SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
     VERSION ${PROJECT_VERSION})
+  target_include_directories(${LIBRARY} INTERFACE
+    $<INSTALL_INTERFACE:include>
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
 
   generate_export_header(${LIBRARY}
     BASE_NAME ${PROJECT_NAME})
@@ -86,6 +90,10 @@ if (CMARK_STATIC)
     OUTPUT_NAME "cmark$<$<BOOL:MSVC>:_static>"
     POSITION_INDEPENDENT_CODE ON
     VERSION ${PROJECT_VERSION})
+  target_include_directories(${STATICLIBRARY} INTERFACE
+    $<INSTALL_INTERFACE:include>
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
 
   if (NOT CMARK_SHARED)
     generate_export_header(${STATICLIBRARY}