Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.9.6 regression] 'find_package(jsoncpp REQUIRED)' fails: Unknown CMake command "check_required_components" #1568

Closed
yurivict opened this issue Sep 13, 2024 · 3 comments · Fixed by #1570

Comments

@yurivict
Copy link

yurivict commented Sep 13, 2024

Describe the bug

$ cat CMakeLists.txt 
find_package(jsoncpp REQUIRED)
CMake Error at /usr/local/lib/cmake/jsoncpp/jsoncppConfig.cmake:31 (check_required_components):
  Unknown CMake command "check_required_components".
Call Stack (most recent call first):
  CMakeLists.txt:1 (find_package)

Desktop (please complete the following information):

  • OS: FreeBSD 14.1
  • cmake-3.29.6
  • Meson version: 1.5.1
@kloczek
Copy link

kloczek commented Sep 27, 2024

It would be good to merge this PR and release new version because issue blocks other projects.

@kloczek
Copy link

kloczek commented Oct 1, 2024

Tested and with that commit it is OK now.
It would be ASP release new version.

@rpavlik
Copy link

rpavlik commented Oct 16, 2024

So that does not actually fully fix the issue. Sure, it will not error immediately, but it will never set jsoncpp_FOUND to TRUE (or FALSE). That line in CMake calls a macro generated into that file that checks for the presence of the variables and files then sets jsoncpp_FOUND. Without that macro, your Meson-generated config file needs to contain other (presumably manually-written) code to perform this.

The meson-generated file:

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was jsoncppConfig.cmake.meson.in ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../.." ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

####################################################################################



add_library(jsoncpp_lib IMPORTED SHARED)
set_target_properties(jsoncpp_lib PROPERTIES
  IMPORTED_LOCATION "${PACKAGE_PREFIX_DIR}/lib/x86_64-linux-gnu/libjsoncpp.so.27"
  INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/include")


include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )

vs the CMake-generated one:

cmake_policy(PUSH)
cmake_policy(VERSION 3.0...3.26)


####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was jsoncppConfig.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################

include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-targets.cmake" )
include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )

check_required_components(JsonCpp)

cmake_policy(POP)

(hmm also the capitalization looks inconsistent, I would have to dig through the docs again to figure out whether it actually affects things.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants