Commit 45dc37b7 authored by jan.koester's avatar jan.koester
Browse files

test

parent fccf1d2c
Loading
Loading
Loading
Loading
+45 −38
Original line number Diff line number Diff line
@@ -2,18 +2,37 @@
# The goal is to set the final target to 'YAML::YAML' in all successful cases.

# 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)

# 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 (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.
# 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)
@@ -21,45 +40,38 @@ else()
        pkg_check_modules(LIBYAML QUIET yaml-0.1)
    endif()

    if(LIBYAML_FOUND)
        message(STATUS "Found libyaml via pkg-config: ${LIBYAML_VERSION}")

    else()
    # Determine if a manual search is necessary
    if(NOT LIBYAML_FOUND)
        # 3. Classic CMake Search (Manual Fallback)
        find_path(LIBYAML_INCLUDE_DIR yaml.h
                     HINTS $ENV{LIBYAML_ROOT} ${CMAKE_PREFIX_PATH} "${CMAKE_PREFIX_PATH}"
                     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(LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY)
            message(STATUS "Found libyaml via classic search: ${LIBYAML_LIBRARY}")
        
        else()
        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 ---
    # --- UNIFIED TARGET CREATION (For pkg-config and Classic) ---
    # This block runs only if we successfully found it manually or via pkg-config
    
    # 5. Create the final modern target 'YAML::YAML'
    if(LIBYAML_FOUND OR (LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY))
        
        # *** HIER IST DIE KORREKTUR: Verwende YAML::YAML (Großbuchstaben) ***
    # 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)
        add_library(YAML::YAML INTERFACE IMPORTED) 
        
        if(LIBYAML_FOUND)
            # Konfiguration aus pkg-config
        if(LIBYAML_FOUND) # pkg-config results
            target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIRS})
            target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARIES})
            
        elseif(LIBYAML_INCLUDE_DIR AND LIBYAML_LIBRARY)
            # Konfiguration aus klassischer Suche
        else() # Classic Search results
            target_include_directories(YAML::YAML INTERFACE ${LIBYAML_INCLUDE_DIR})
            target_link_libraries(YAML::YAML INTERFACE ${LIBYAML_LIBRARY})
            
@@ -69,13 +81,8 @@ 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.")
    message(STATUS "libyaml is successfully available via target YAML::YAML.")
else()
        message(FATAL_ERROR "Failed to configure final target YAML::YAML.") 
    endif()
    # This should now only happen if the CONFIG search found something unrecognized
    message(FATAL_ERROR "libyaml found, but failed to create the final target YAML::YAML.")
endif()
 No newline at end of file