Skip to content

Commit 19d4b2e

Browse files
author
Clemens Vasters
committed
fix(c): exclude cJSON from install targets
- Use FetchContent_Populate + add_subdirectory with EXCLUDE_FROM_ALL instead of FetchContent_MakeAvailable to prevent cJSON's install() commands from running during 'cmake --install' - Change cJSON linkage from PUBLIC to PRIVATE since it's statically linked into the shared library - Set ENABLE_TARGET_EXPORT OFF and ENABLE_CJSON_UNINSTALL OFF to further prevent cJSON from adding install targets - Set ENABLE_CUSTOM_COMPILER_FLAGS OFF to prevent cJSON's strict compiler flags from conflicting with our project's flags - Remove non-existent ENABLE_CJSON_INSTALL option This fixes the release job failure where cJSON was trying to install to /usr/local which requires elevated permissions on GitHub Actions runners.
1 parent 409ad00 commit 19d4b2e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

c/CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,27 @@ if(JS_FETCH_DEPENDENCIES)
7272
)
7373
endif()
7474

75-
# Configure cJSON options
75+
# Configure cJSON options before populating
7676
set(ENABLE_CJSON_TEST OFF CACHE BOOL "" FORCE)
77-
set(ENABLE_CJSON_INSTALL OFF CACHE BOOL "" FORCE)
7877
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
7978
set(BUILD_SHARED_AND_STATIC_LIBS OFF CACHE BOOL "" FORCE)
8079
set(CJSON_OVERRIDE_BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
8180
set(CJSON_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
81+
# Disable cJSON's target export to prevent install conflicts
82+
set(ENABLE_TARGET_EXPORT OFF CACHE BOOL "" FORCE)
83+
set(ENABLE_CJSON_UNINSTALL OFF CACHE BOOL "" FORCE)
84+
# Disable cJSON's custom compiler flags to avoid conflicts with our project flags
85+
set(ENABLE_CUSTOM_COMPILER_FLAGS OFF CACHE BOOL "" FORCE)
8286

83-
FetchContent_MakeAvailable(cjson)
87+
# Use FetchContent_Populate + add_subdirectory with EXCLUDE_FROM_ALL
88+
# This prevents cJSON's install() commands from running at install time
89+
# The cjson target is still available for linking
90+
FetchContent_GetProperties(cjson)
91+
if(NOT cjson_POPULATED)
92+
FetchContent_Populate(cjson)
93+
# EXCLUDE_FROM_ALL prevents cJSON install targets from being part of the default install
94+
add_subdirectory(${cjson_SOURCE_DIR} ${cjson_BINARY_DIR} EXCLUDE_FROM_ALL)
95+
endif()
8496

8597
# Create wrapper include directory for <cjson/cJSON.h> compatibility
8698
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/cjson")
@@ -129,8 +141,10 @@ target_include_directories(json_structure
129141
$<INSTALL_INTERFACE:include>
130142
)
131143

144+
# cJSON is statically linked into the shared library, so it's PRIVATE
145+
# This prevents cjson from being part of the install export set
132146
target_link_libraries(json_structure
133-
PUBLIC cjson
147+
PRIVATE cjson
134148
)
135149

136150
# Link pthread on Unix systems for thread synchronization

0 commit comments

Comments
 (0)