Loading backends/CMakeLists.txt +5 −3 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ include_directories( find_package(YAML REQUIRED) # The conditional check needs a standard CMake variable check, not a dereference. if(YAML_FOUND) set( yamlconfsrc "yaml/yamlconf.cpp") add_library(yamlconf SHARED ${yamlconfsrc}) Loading @@ -27,6 +28,7 @@ find_package(YAML REQUIRED) RUNTIME DESTINATION bin LIBRARY DESTINATION lib/confplus/backend NAMELINK_SKIP ) endif() # --- INIPARSER BACKEND (Corrected) --- find_package(INIPARSER) Loading @@ -42,9 +44,9 @@ if(INIPARSER_FOUND) # We remove target_include_directories and rely on INIPARSER::INIPARSER. if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") target_link_libraries(iniconf PRIVATE confplus ${INIPARSER_LIBRARY} kernel32.lib) target_link_libraries(iniconf PRIVATE confplus iniparser::iniparser kernel32.lib) else() target_link_libraries(iniconf PRIVATE confplus ${INIPARSER_LIBRARY} dl) target_link_libraries(iniconf PRIVATE confplus iniparser::iniparser dl) endif() install(TARGETS iniconf Loading cmake/FindYAML.cmake +41 −91 Original line number Diff line number Diff line # CMake strategy to find the C library libyaml using multiple approaches: # The goal is to set the final target to 'YAML::YAML' in all successful cases. # CMake strategy to find the C library libyaml using ONLY the classic search # and creating the modern target 'YAML::YAML'. # 1. CONFIG Package Search (e.g., vcpkg, Conan) # Check for both 'yaml' (common vcpkg) and 'LibYAML' (sometimes provided by system) find_package(yaml CONFIG QUIET) find_package(LibYAML CONFIG QUIET) # Determine if the CONFIG search succeeded if(YAML_FOUND OR LibYAML_FOUND) message(STATUS "Found libyaml via CONFIG.") # --- ENSURE UPPERCASE ALIAS --- # Most vcpkg/Conan config files define 'yaml::yaml' (lowercase). # We must ensure the required 'YAML::YAML' (uppercase) target exists. # 1. If the lowercase target exists, create the uppercase alias if(TARGET yaml::yaml AND NOT TARGET YAML::YAML) add_library(YAML::YAML ALIAS yaml::yaml) message(STATUS "Created ALIAS target YAML::YAML -> yaml::yaml.") # 2. Check if the uppercase target already exists (e.g., from LibYAML config) elseif(TARGET LibYAML::LibYAML AND NOT TARGET YAML::YAML) add_library(YAML::YAML ALIAS LibYAML::LibYAML) message(STATUS "Created ALIAS target YAML::YAML -> LibYAML::LibYAML.") # 3. Handle the case where the CONFIG script already defined YAML::YAML elseif(TARGET YAML::YAML) # Target already exists, no action needed. else() message(FATAL_ERROR "libyaml found via CONFIG, but no recognizable target (yaml::yaml or YAML::YAML) was created.") endif() # Fallback to Manual Search else() # 2. pkg-config Search (Common on Linux/MSYS) find_package(PkgConfig QUIET) if(PkgConfig_FOUND) pkg_check_modules(LIBYAML QUIET yaml-0.1) endif() # Determine if a manual search is necessary if(NOT LIBYAML_FOUND) # 3. Classic CMake Search (Manual Fallback) # --- 1. Classic CMake Search (Manual Fallback) --- find_path(LIBYAML_INCLUDE_DIR yaml.h HINTS $ENV{LIBYAML_ROOT} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES include ) # Note: 'HINTS ... "${CMAKE_PREFIX_PATH}"' is redundant with PATH_SUFFIXES 'lib' and CMAKE_PREFIX_PATH find_library(LIBYAML_LIBRARY NAMES yaml libyaml HINTS $ENV{LIBYAML_ROOT} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES lib ) # 4. Check results from the classic search if(NOT (LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY)) message(FATAL_ERROR "libyaml (C) not found. Please set LIBYAML_ROOT or install it.") endif() endif() # --- UNIFIED TARGET CREATION (For pkg-config and Classic) --- # This block runs only if we successfully found it manually or via pkg-config # --- 2. Check Results and Set Required Variables --- if(LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY) message(STATUS "Found libyaml (C) headers: ${LIBYAML_INCLUDE_DIR}") message(STATUS "Found libyaml (C) library: ${LIBYAML_LIBRARY}") # 5. Create the final modern target 'YAML::YAML' (Uppercase) if(NOT TARGET YAML::YAML) # Only create if not already handled by CONFIG (unlikely here, but safe) # --- 3. EXPORT Modern CMake Target --- if(NOT TARGET YAML::YAML) # Create an INTERFACE IMPORTED target for modern linking add_library(YAML::YAML INTERFACE IMPORTED) if(LIBYAML_FOUND) # pkg-config results target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIRS}) target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARIES}) else() # Classic Search results # Set the properties for the modern target target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIR}) target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARY}) endif() endif() message(STATUS "SUCCESS: Created modern IMPORTED target YAML::YAML.") endif() # In your custom FindYAML logic, *immediately* after find_package(yaml CONFIG QUIET) # Define YAML_FOUND for use outside this script (if needed by other Find modules) set(YAML_FOUND TRUE CACHE BOOL "libyaml C library found." FORCE) if(YAML_FOUND) # Check if the CONFIG file created the lowercase target if(TARGET yaml::yaml AND NOT TARGET YAML::YAML) # Create the ALIAS that backends/CMakeLists.txt needs add_library(YAML::YAML ALIAS yaml::yaml) message(STATUS "SUCCESS: Created ALIAS target YAML::YAML -> yaml::yaml.") # ... (Other checks for LibYAML::LibYAML, etc.) ... elseif(NOT TARGET YAML::YAML) # If the CONFIG search found the package but didn't create a target we recognize, # the build will fail. Log this for debugging. message(WARNING "libyaml found via CONFIG, but failed to create or find target YAML::YAML.") # --- 4. Failure Condition --- else() # Check if the variables are set to notify the user what is missing if(NOT LIBYAML_INCLUDE_DIR) message(STATUS "libyaml header (yaml.h) NOT found.") endif() else message(FATAL_ERROR "yaml not found") if(NOT LIBYAML_LIBRARY) message(STATUS "libyaml library NOT found.") endif() # FATAL_ERROR only if necessary message(FATAL_ERROR "libyaml (C) not found. Please set LIBYAML_ROOT or ensure files are in CMAKE_PREFIX_PATH.") endif() # The final goal in your consuming CMakeLists.txt: # target_link_libraries(yamlconf PRIVATE YAML::YAML) No newline at end of file Loading
backends/CMakeLists.txt +5 −3 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ include_directories( find_package(YAML REQUIRED) # The conditional check needs a standard CMake variable check, not a dereference. if(YAML_FOUND) set( yamlconfsrc "yaml/yamlconf.cpp") add_library(yamlconf SHARED ${yamlconfsrc}) Loading @@ -27,6 +28,7 @@ find_package(YAML REQUIRED) RUNTIME DESTINATION bin LIBRARY DESTINATION lib/confplus/backend NAMELINK_SKIP ) endif() # --- INIPARSER BACKEND (Corrected) --- find_package(INIPARSER) Loading @@ -42,9 +44,9 @@ if(INIPARSER_FOUND) # We remove target_include_directories and rely on INIPARSER::INIPARSER. if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") target_link_libraries(iniconf PRIVATE confplus ${INIPARSER_LIBRARY} kernel32.lib) target_link_libraries(iniconf PRIVATE confplus iniparser::iniparser kernel32.lib) else() target_link_libraries(iniconf PRIVATE confplus ${INIPARSER_LIBRARY} dl) target_link_libraries(iniconf PRIVATE confplus iniparser::iniparser dl) endif() install(TARGETS iniconf Loading
cmake/FindYAML.cmake +41 −91 Original line number Diff line number Diff line # CMake strategy to find the C library libyaml using multiple approaches: # The goal is to set the final target to 'YAML::YAML' in all successful cases. # CMake strategy to find the C library libyaml using ONLY the classic search # and creating the modern target 'YAML::YAML'. # 1. CONFIG Package Search (e.g., vcpkg, Conan) # Check for both 'yaml' (common vcpkg) and 'LibYAML' (sometimes provided by system) find_package(yaml CONFIG QUIET) find_package(LibYAML CONFIG QUIET) # Determine if the CONFIG search succeeded if(YAML_FOUND OR LibYAML_FOUND) message(STATUS "Found libyaml via CONFIG.") # --- ENSURE UPPERCASE ALIAS --- # Most vcpkg/Conan config files define 'yaml::yaml' (lowercase). # We must ensure the required 'YAML::YAML' (uppercase) target exists. # 1. If the lowercase target exists, create the uppercase alias if(TARGET yaml::yaml AND NOT TARGET YAML::YAML) add_library(YAML::YAML ALIAS yaml::yaml) message(STATUS "Created ALIAS target YAML::YAML -> yaml::yaml.") # 2. Check if the uppercase target already exists (e.g., from LibYAML config) elseif(TARGET LibYAML::LibYAML AND NOT TARGET YAML::YAML) add_library(YAML::YAML ALIAS LibYAML::LibYAML) message(STATUS "Created ALIAS target YAML::YAML -> LibYAML::LibYAML.") # 3. Handle the case where the CONFIG script already defined YAML::YAML elseif(TARGET YAML::YAML) # Target already exists, no action needed. else() message(FATAL_ERROR "libyaml found via CONFIG, but no recognizable target (yaml::yaml or YAML::YAML) was created.") endif() # Fallback to Manual Search else() # 2. pkg-config Search (Common on Linux/MSYS) find_package(PkgConfig QUIET) if(PkgConfig_FOUND) pkg_check_modules(LIBYAML QUIET yaml-0.1) endif() # Determine if a manual search is necessary if(NOT LIBYAML_FOUND) # 3. Classic CMake Search (Manual Fallback) # --- 1. Classic CMake Search (Manual Fallback) --- find_path(LIBYAML_INCLUDE_DIR yaml.h HINTS $ENV{LIBYAML_ROOT} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES include ) # Note: 'HINTS ... "${CMAKE_PREFIX_PATH}"' is redundant with PATH_SUFFIXES 'lib' and CMAKE_PREFIX_PATH find_library(LIBYAML_LIBRARY NAMES yaml libyaml HINTS $ENV{LIBYAML_ROOT} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES lib ) # 4. Check results from the classic search if(NOT (LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY)) message(FATAL_ERROR "libyaml (C) not found. Please set LIBYAML_ROOT or install it.") endif() endif() # --- UNIFIED TARGET CREATION (For pkg-config and Classic) --- # This block runs only if we successfully found it manually or via pkg-config # --- 2. Check Results and Set Required Variables --- if(LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY) message(STATUS "Found libyaml (C) headers: ${LIBYAML_INCLUDE_DIR}") message(STATUS "Found libyaml (C) library: ${LIBYAML_LIBRARY}") # 5. Create the final modern target 'YAML::YAML' (Uppercase) if(NOT TARGET YAML::YAML) # Only create if not already handled by CONFIG (unlikely here, but safe) # --- 3. EXPORT Modern CMake Target --- if(NOT TARGET YAML::YAML) # Create an INTERFACE IMPORTED target for modern linking add_library(YAML::YAML INTERFACE IMPORTED) if(LIBYAML_FOUND) # pkg-config results target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIRS}) target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARIES}) else() # Classic Search results # Set the properties for the modern target target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIR}) target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARY}) endif() endif() message(STATUS "SUCCESS: Created modern IMPORTED target YAML::YAML.") endif() # In your custom FindYAML logic, *immediately* after find_package(yaml CONFIG QUIET) # Define YAML_FOUND for use outside this script (if needed by other Find modules) set(YAML_FOUND TRUE CACHE BOOL "libyaml C library found." FORCE) if(YAML_FOUND) # Check if the CONFIG file created the lowercase target if(TARGET yaml::yaml AND NOT TARGET YAML::YAML) # Create the ALIAS that backends/CMakeLists.txt needs add_library(YAML::YAML ALIAS yaml::yaml) message(STATUS "SUCCESS: Created ALIAS target YAML::YAML -> yaml::yaml.") # ... (Other checks for LibYAML::LibYAML, etc.) ... elseif(NOT TARGET YAML::YAML) # If the CONFIG search found the package but didn't create a target we recognize, # the build will fail. Log this for debugging. message(WARNING "libyaml found via CONFIG, but failed to create or find target YAML::YAML.") # --- 4. Failure Condition --- else() # Check if the variables are set to notify the user what is missing if(NOT LIBYAML_INCLUDE_DIR) message(STATUS "libyaml header (yaml.h) NOT found.") endif() else message(FATAL_ERROR "yaml not found") if(NOT LIBYAML_LIBRARY) message(STATUS "libyaml library NOT found.") endif() # FATAL_ERROR only if necessary message(FATAL_ERROR "libyaml (C) not found. Please set LIBYAML_ROOT or ensure files are in CMAKE_PREFIX_PATH.") endif() # The final goal in your consuming CMakeLists.txt: # target_link_libraries(yamlconf PRIVATE YAML::YAML) No newline at end of file