From 716651e5e4692942c07a23526724a47ff00716bc Mon Sep 17 00:00:00 2001 From: Luis Caro Campos <3535649+jcar87@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:09:47 +0000 Subject: [PATCH 1/2] Compute CMAKE_PROGRAM_PATH from returned json --- conan_provider.cmake | 39 +++++++++++++++++++++++++++++++++++++++ example/CMakeLists.txt | 10 ++++++++++ example/conanfile.txt | 5 ++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index cba4606c..c3e239bf 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -451,8 +451,46 @@ function(conan_install) # success set_property(GLOBAL PROPERTY CONAN_INSTALL_SUCCESS TRUE) + + conan_set_program_path() + + list(PREPEND CMAKE_PROGRAM_PATH ${_CONAN_PROGRAM_PATH}) + set(CMAKE_PROGRAM_PATH ${CMAKE_PROGRAM_PATH} PARENT_SCOPE) + endfunction() +macro(conan_set_program_path) + set(_CONAN_PROGRAM_PATH "") + + message("${conan_stdout}") + string(JSON _conan_graph_nodes_length LENGTH ${conan_stdout} graph nodes) + math(EXPR _conan_graph_nodes_length "${_conan_graph_nodes_length} - 1") + foreach(_node_number RANGE ${_conan_graph_nodes_length}) + + string(JSON _dep_binary GET ${conan_stdout} graph nodes ${_node_number} binary) + string(JSON _dep_context GET ${conan_stdout} graph nodes ${_node_number} context) + + if(NOT _dep_binary STREQUAL "Cache" OR NOT _dep_context STREQUAL "build") + continue() + endif() + + string(JSON _current_node_length LENGTH ${conan_stdout} graph nodes ${_node_number} cpp_info) + math(EXPR _current_node_components "${_current_node_length} - 1") + foreach(_component RANGE ${_current_node_components}) + string(JSON _current_component_name MEMBER ${conan_stdout} graph nodes ${_node_number} cpp_info ${_component}) + string(JSON _current_component_bindirs GET ${conan_stdout} graph nodes ${_node_number} cpp_info ${_current_component_name} bindirs) + string(JSON _bindirs_length LENGTH ${_current_component_bindirs}) + math(EXPR _bindirs_length "${_bindirs_length} - 1") + foreach(_bindir_index RANGE ${_bindirs_length}) + string(JSON _bindir GET ${_current_component_bindirs} ${_bindir_index}) + list(APPEND _CONAN_PROGRAM_PATH ${_bindir}) + endforeach() + endforeach() + endforeach() + + message("conan_program_path: ${_CONAN_PROGRAM_PATH}") + list(REMOVE_DUPLICATES _CONAN_PROGRAM_PATH) +endmacro() function(conan_get_version conan_command conan_current_version) execute_process( @@ -542,6 +580,7 @@ macro(conan_provide_dependency method package_name) if(NOT _multiconfig_generator) message(STATUS "CMake-Conan: Installing single configuration ${CMAKE_BUILD_TYPE}") conan_install(${_host_profile_flags} ${_build_profile_flags} ${CONAN_INSTALL_ARGS} ${generator}) + message("CMAKE_PROGRAM_PATH yyy: ${CMAKE_PROGRAM_PATH}") else() message(STATUS "CMake-Conan: Installing both Debug and Release") conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=Release ${CONAN_INSTALL_ARGS} ${generator}) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 150fc98c..ae516ade 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -4,7 +4,17 @@ project(FormatOutput LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) +set(CMAKE_PROGRAM_PATH "/path/to/foo/bar") + find_package(fmt REQUIRED) +message("CMAKE_PROGRAM_PATH: ${CMAKE_PROGRAM_PATH}") +find_program(CMAKE_CXX_CPPCHECK cppcheck NAMES cppcheck) +if(NOT CMAKE_CXX_CPPCHECK) + message(FATAL_ERROR "Unable to locate CPPCHECK") +else() + message("Cppcheck found: ${CMAKE_CXX_CPPCHECK}") +endif() + add_executable(main main.cpp) target_link_libraries(main PRIVATE fmt::fmt) diff --git a/example/conanfile.txt b/example/conanfile.txt index 85f12618..3cecfd91 100644 --- a/example/conanfile.txt +++ b/example/conanfile.txt @@ -1,5 +1,8 @@ [requires] -fmt/9.1.0 +fmt/[>10] + +[tool_requires] +cppcheck/[>=2.13 <3] [layout] cmake_layout From f6be8ef325a77248df6c0b7aa9b07d2675e298e2 Mon Sep 17 00:00:00 2001 From: Luis Caro Campos <3535649+jcar87@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:49:51 +0000 Subject: [PATCH 2/2] fixes --- conan_provider.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index c3e239bf..7a9b7bc8 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -470,7 +470,7 @@ macro(conan_set_program_path) string(JSON _dep_binary GET ${conan_stdout} graph nodes ${_node_number} binary) string(JSON _dep_context GET ${conan_stdout} graph nodes ${_node_number} context) - if(NOT _dep_binary STREQUAL "Cache" OR NOT _dep_context STREQUAL "build") + if(_dep_binary STREQUAL "Skip" OR NOT _dep_context STREQUAL "build") continue() endif() @@ -488,7 +488,6 @@ macro(conan_set_program_path) endforeach() endforeach() - message("conan_program_path: ${_CONAN_PROGRAM_PATH}") list(REMOVE_DUPLICATES _CONAN_PROGRAM_PATH) endmacro()