Loading cmake/Findjson-c.cmake 0 → 100644 +87 −0 Changes for cmake/Findjson-c.cmake: 87 added lines, 0 removed lines. Original line number Diff line number Diff line # ===================================================================== # Findjson-c.cmake (Shared Library Version - Refined for Windows DLL Paths) # ===================================================================== include(FindPackageHandleStandardArgs) # ----------------------------------------------------------------------------- # 1. Find Header and Link Libraries # ----------------------------------------------------------------------------- # Find the header file (e.g., json-c/json.h or json.h) find_path(JSONC_INCLUDE_DIR NAMES json-c/json.h json.h HINTS ENV JSONC_ROOT PATH_SUFFIXES include ) # Find the shared library file (.lib on Windows, .so/.dylib elsewhere) # json-c library names can vary (e.g., json-c, json-c-0, json-c.so.0) find_library(JSONC_LIBRARY NAMES json-c json-c-0) # ----------------------------------------------------------------------------- # 2. Handle Required Arguments # ----------------------------------------------------------------------------- find_package_handle_standard_args(JsonC FOUND_VAR JSONC_FOUND REQUIRED_VARS JSONC_INCLUDE_DIR JSONC_LIBRARY FAIL_MESSAGE "Could NOT find json-c shared library or headers." ) # ----------------------------------------------------------------------------- # 3. Define Imported Shared Target # ----------------------------------------------------------------------------- if(JSONC_FOUND) # 1. Define the target as SHARED IMPORTED # We use a single target since json-c is generally one library. add_library(JsonC::JsonC SHARED IMPORTED) # 2. Set the public interface (headers) set_target_properties(JsonC::JsonC PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIR}" ) # 3. Set the location properties if(WIN32) # Set IMPORTED_IMPLIB (the .lib) for linking set_target_properties(JsonC::JsonC PROPERTIES IMPORTED_IMPLIB "${JSONC_LIBRARY}" ) # CRITICAL FOR DLL PATH RESOLUTION: Determine the DLL path. # We assume a common structure: DLLs are in 'bin' and .lib are in 'lib'. get_filename_component(_LIB_DIR "${JSONC_LIBRARY}" DIRECTORY) get_filename_component(_PARENT_DIR "${_LIB_DIR}" DIRECTORY) # Determine the DLL name (strip prefix/suffix, often just 'json-c') get_filename_component(_LIB_NAME_WE "${JSONC_LIBRARY}" NAME_WE) string(REGEX REPLACE "^lib" "" _DLL_NAME_BASE "${_LIB_NAME_WE}") # 💡 Heuristic: Assuming DLL is in <parent>/bin/ # Set IMPORTED_LOCATION for both Debug and Release configurations set_target_properties(JsonC::JsonC PROPERTIES # Assuming VCPKG/standard installs put the DLL in bin/ IMPORTED_LOCATION_RELEASE "${_PARENT_DIR}/bin/${_DLL_NAME_BASE}.dll" # Assuming a common debug suffix 'd' (e.g., json-cd.dll) IMPORTED_LOCATION_DEBUG "${_PARENT_DIR}/bin/${_DLL_NAME_BASE}d.dll" # Add RelWithDebInfo as well, which might have the same DLL name as Release IMPORTED_LOCATION_RELWITHDEBINFO "${_PARENT_DIR}/bin/${_DLL_NAME_BASE}.dll" ) else() # Non-Windows systems: link file is the runtime file set_target_properties(JsonC::JsonC PROPERTIES IMPORTED_LOCATION "${JSONC_LIBRARY}" ) endif() endif() # Hide internal variables from the CMake GUI mark_as_advanced( JSONC_INCLUDE_DIR JSONC_LIBRARY ) No newline at end of file Loading
cmake/Findjson-c.cmake 0 → 100644 +87 −0 Changes for cmake/Findjson-c.cmake: 87 added lines, 0 removed lines. Original line number Diff line number Diff line # ===================================================================== # Findjson-c.cmake (Shared Library Version - Refined for Windows DLL Paths) # ===================================================================== include(FindPackageHandleStandardArgs) # ----------------------------------------------------------------------------- # 1. Find Header and Link Libraries # ----------------------------------------------------------------------------- # Find the header file (e.g., json-c/json.h or json.h) find_path(JSONC_INCLUDE_DIR NAMES json-c/json.h json.h HINTS ENV JSONC_ROOT PATH_SUFFIXES include ) # Find the shared library file (.lib on Windows, .so/.dylib elsewhere) # json-c library names can vary (e.g., json-c, json-c-0, json-c.so.0) find_library(JSONC_LIBRARY NAMES json-c json-c-0) # ----------------------------------------------------------------------------- # 2. Handle Required Arguments # ----------------------------------------------------------------------------- find_package_handle_standard_args(JsonC FOUND_VAR JSONC_FOUND REQUIRED_VARS JSONC_INCLUDE_DIR JSONC_LIBRARY FAIL_MESSAGE "Could NOT find json-c shared library or headers." ) # ----------------------------------------------------------------------------- # 3. Define Imported Shared Target # ----------------------------------------------------------------------------- if(JSONC_FOUND) # 1. Define the target as SHARED IMPORTED # We use a single target since json-c is generally one library. add_library(JsonC::JsonC SHARED IMPORTED) # 2. Set the public interface (headers) set_target_properties(JsonC::JsonC PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIR}" ) # 3. Set the location properties if(WIN32) # Set IMPORTED_IMPLIB (the .lib) for linking set_target_properties(JsonC::JsonC PROPERTIES IMPORTED_IMPLIB "${JSONC_LIBRARY}" ) # CRITICAL FOR DLL PATH RESOLUTION: Determine the DLL path. # We assume a common structure: DLLs are in 'bin' and .lib are in 'lib'. get_filename_component(_LIB_DIR "${JSONC_LIBRARY}" DIRECTORY) get_filename_component(_PARENT_DIR "${_LIB_DIR}" DIRECTORY) # Determine the DLL name (strip prefix/suffix, often just 'json-c') get_filename_component(_LIB_NAME_WE "${JSONC_LIBRARY}" NAME_WE) string(REGEX REPLACE "^lib" "" _DLL_NAME_BASE "${_LIB_NAME_WE}") # 💡 Heuristic: Assuming DLL is in <parent>/bin/ # Set IMPORTED_LOCATION for both Debug and Release configurations set_target_properties(JsonC::JsonC PROPERTIES # Assuming VCPKG/standard installs put the DLL in bin/ IMPORTED_LOCATION_RELEASE "${_PARENT_DIR}/bin/${_DLL_NAME_BASE}.dll" # Assuming a common debug suffix 'd' (e.g., json-cd.dll) IMPORTED_LOCATION_DEBUG "${_PARENT_DIR}/bin/${_DLL_NAME_BASE}d.dll" # Add RelWithDebInfo as well, which might have the same DLL name as Release IMPORTED_LOCATION_RELWITHDEBINFO "${_PARENT_DIR}/bin/${_DLL_NAME_BASE}.dll" ) else() # Non-Windows systems: link file is the runtime file set_target_properties(JsonC::JsonC PROPERTIES IMPORTED_LOCATION "${JSONC_LIBRARY}" ) endif() endif() # Hide internal variables from the CMake GUI mark_as_advanced( JSONC_INCLUDE_DIR JSONC_LIBRARY ) No newline at end of file