Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,45 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be a bit cleaner to do a function and "return" the variable to be used later

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(_dep_binary STREQUAL "Skip" OR NOT _dep_context STREQUAL "build")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't you play safer doing a comparison against a lowercase value?:

if(_dep_binary_lowercase STREQUAL "skip" OR NOT _dep_context_lowercase STREQUAL "build")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even defining those "Skip", "build"... somewhere as constants. Although that may be overkill. 😄 This type of code always looks to me like a bit like "magic numbers".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part of Conan's json formatter, so it's essentially a public API - if this ever changed in Conan, our tests (in Conan) would fail straight away so we would know that would be a breaking change (minimising the chance of this ever happening - so not sure we can something by doing lowercase).

they could be constants but then we would have more indirection given how CMake expands variables but I'll consider that

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation! And roger that CMake code is by itself complicated enough to introduce further indirections.

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})
Comment on lines +479 to +486
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Master of CMake! I am happy that I didn't have to write this code😄

endforeach()
endforeach()
endforeach()

list(REMOVE_DUPLICATES _CONAN_PROGRAM_PATH)
endmacro()

function(conan_get_version conan_command conan_current_version)
execute_process(
Expand Down Expand Up @@ -542,6 +579,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})
Expand Down
10 changes: 10 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion example/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[requires]
fmt/9.1.0
fmt/[>10]

[tool_requires]
cppcheck/[>=2.13 <3]

[layout]
cmake_layout