conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
958 stars 1.76k forks source link

[package] flatbuffers/2.0.x: Updating flatbuffers does not update FLATBUFFERS_FLATC_EXECUTABLE #11390

Open mjvankampen opened 2 years ago

mjvankampen commented 2 years ago

Package and Environment Details

Conan profile

No response

Steps to reproduce

Change between flatbuffer version without deleting cache. Updated flatbuffers package is detected, but the FLATBUFFERS_FLATC_EXECUTABLE is not updated. I guess as flatbuffers::flatc still exists.

if(NOT TARGET flatbuffers::flatc)
    if(CMAKE_CROSSCOMPILING)
        find_program(FLATBUFFERS_FLATC_EXECUTABLE
            NAMES flatc
            PATHS ENV PATH
            NO_DEFAULT_PATH
        )
    else()
        find_program(FLATBUFFERS_FLATC_EXECUTABLE
            NAMES flatc
            PATHS "${CMAKE_CURRENT_LIST_DIR}/../../bin/"
            NO_DEFAULT_PATH
        )
    endif()
    # TODO: In conan v2 with CMakeToolchain, can be replaced by:
    # find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc)
    # # Nice enough to handle flatbuffers not in build_requires for native build
    # if(NOT FLATBUFFERS_FLATC_EXECUTABLE AND NOT CMAKE_CROSSCOMPILING)
    #     find_program(FLATBUFFERS_FLATC_EXECUTABLE
    #         NAMES flatc
    #         PATHS "${CMAKE_CURRENT_LIST_DIR}/../../bin/"
    #         NO_DEFAULT_PATH
    #     )
    # endif()

    if(FLATBUFFERS_FLATC_EXECUTABLE)
        get_filename_component(FLATBUFFERS_FLATC_EXECUTABLE "${FLATBUFFERS_FLATC_EXECUTABLE}" ABSOLUTE)
        add_executable(flatbuffers::flatc IMPORTED)
        set_property(TARGET flatbuffers::flatc PROPERTY IMPORTED_LOCATION ${FLATBUFFERS_FLATC_EXECUTABLE})
    endif()
endif()

Logs

No response

himikof commented 2 years ago

An easy fix on CMake >= 3.21 would be to add NO_CACHE option to find_program calls: https://cmake.org/cmake/help/latest/command/find_program.html. There should be no reason to store the path to Conan-built flatc in the CMake cache.

Otherwise, why is the find_program(... PATHS "${CMAKE_CURRENT_LIST_DIR}/../../bin/" NO_DEFAULT_PATH) call even needed if we already know both the path and the executable name? I think it could be replaced with something like

set(FLATBUFFERS_FLATC_EXECUTABLE "${CMAKE_CURRENT_LIST_DIR}/../../bin/flatc${CMAKE_EXECUTABLE_SUFFIX}"

This is a regression since https://github.com/conan-io/conan-center-index/pull/9292, when the find_program calls were introduced.