Commit f75da4c3 authored by jan.koester's avatar jan.koester
Browse files

test

parent 16374e8c
Loading
Loading
Loading
Loading
+31 −21
Original line number Diff line number Diff line
# CMake strategy to find the C library libyaml using multiple approaches:
# 1. Config/Package Manager (Modern)
# 2. pkg-config (System Tooling)
# 3. Classic CMake Search (Manual)

# The goal is to set the final target to 'yaml::yaml' in all successful cases.
# The goal is to set the final target to 'YAML::YAML' in all successful cases.

# 1. CONFIG Package Search (e.g., vcpkg, Conan)
# This is the most robust method if a config file is available.
find_package(yaml CONFIG QUIET)

# Achtung: Wenn CONFIG gefunden wird, existiert das Target eventuell als 'yaml::yaml' (Kleinbuchstaben)
# oder 'YAML::YAML' (Großbuchstaben), je nach Konfigurationsdatei.
# Wir gehen hier davon aus, dass wir den Namen 'YAML::YAML' bevorzugen.
if(yaml_FOUND)
    message(STATUS "Found libyaml via CONFIG: yaml::yaml")
    # If found via CONFIG, the target yaml::yaml already exists and is configured.
    message(STATUS "Found libyaml via CONFIG: YAML::YAML (Assuming alias or correct naming)")
    # Wenn find_package(yaml) ein Target 'yaml::yaml' liefert,
    # kann hier ein ALIAS erstellt werden, um 'YAML::YAML' zu gewährleisten:
    # add_library(YAML::YAML ALIAS yaml::yaml)
    # Für diesen Fall lassen wir es, da oft das CONFIG-Script bereits den korrekten Namen liefert.
    
else()
    # 2. pkg-config Search (Common on Linux/MSYS)
    find_package(PkgConfig QUIET)
    if(PkgConfig_FOUND)
        # Check for the common pkg-config name 'yaml-0.1'
        pkg_check_modules(LIBYAML QUIET yaml-0.1)
    endif()

@@ -29,7 +29,6 @@ else()
        find_path(LIBYAML_INCLUDE_DIR yaml.h
                     HINTS $ENV{LIBYAML_ROOT} ${CMAKE_PREFIX_PATH})
        
        # Search for library files (e.g., yaml.lib, libyaml.a, libyaml.so)
        find_library(LIBYAML_LIBRARY NAMES yaml libyaml
                     HINTS $ENV{LIBYAML_ROOT} ${CMAKE_PREFIX_PATH})
                     
@@ -38,30 +37,41 @@ else()
            message(STATUS "Found libyaml via classic search: ${LIBYAML_LIBRARY}")
        
        else()
            # If all methods fail, stop the configuration process.
            message(FATAL_ERROR "libyaml (C) not found. Please set LIBYAML_ROOT or install it.")
        endif()
    endif()
    
    # --- UNIFIED TARGET CREATION ---
    
    # 5. Create the final modern target 'yaml::yaml' 
    #    This block executes only if either pkg-config or the manual search succeeded.
    # 5. Create the final modern target 'YAML::YAML'
    if(LIBYAML_FOUND OR (LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY))
        
        # Define the target as INTERFACE IMPORTED, as it only transfers link/include information.
        add_library(yaml::yaml INTERFACE IMPORTED) 
        # *** HIER IST DIE KORREKTUR: Verwende YAML::YAML (Großbuchstaben) ***
        add_library(YAML::YAML INTERFACE IMPORTED) 
        
        if(LIBYAML_FOUND)
            # Apply configuration from pkg-config variables (LIBYAML_INCLUDE_DIRS, etc.)
            target_include_directories(yaml::yaml INTERFACE ${LIBYAML_INCLUDE_DIRS})
            target_link_libraries(yaml::yaml INTERFACE ${LIBYAML_LIBRARIES})
            # Konfiguration aus pkg-config
            target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIRS})
            target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARIES})
            
        elseif(LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY)
            # Apply configuration from classic search variables
            target_include_directories(yaml::yaml INTERFACE ${LIBYAML_INCLUDE_DIR})
            target_link_libraries(yaml::yaml INTERFACE ${LIBYAML_LIBRARY})
            # Konfiguration aus klassischer Suche
            target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIR})
            target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARY})
            
        endif()
    endif()
endif()

# 6. Finaler Status und Ziel-Überprüfung
if(TARGET YAML::YAML)
    message(STATUS "libyaml is available via target YAML::YAML.")
else()
    # Wenn CONFIG gefunden wurde, aber kein Alias auf YAML::YAML existiert, könnte dies fehlschlagen.
    # Wenn CONFIG nicht gefunden wurde, sollte der FATAL_ERROR im Code oben gegriffen haben.
    if(yaml_FOUND)
        message(FATAL_ERROR "libyaml found via CONFIG, but target YAML::YAML is not defined. Check the CONFIG script's target name.")
    else()
        message(FATAL_ERROR "Failed to configure final target YAML::YAML.") 
    endif()
endif()
 No newline at end of file