有没有办法为包系统提供的库生成find< ...> .cmake文件?

时间:2017-01-31 11:13:45

标签: ubuntu cmake

理论上,如果尚未内置到cmake中,它应该是直截了当的。毕竟,[{"_id":"test","label":"test","descrizione":"descrizione test","url":"http://www.virgilio.it","tipoProfilo":"NGPFNL","periodoValidazione":370,"direct":false,"preValid":false,"deleted":false},{"_id":"test2","label":"test2","descrizione":"descr test2","url":"http://www.google.com","tipoProfilo":"NGPFNL","periodoValidazione":123,"direct":false,"preValid":false,"deleted":false}] apt知道标头和目标文件的位置,因此它应该是可行的。

我知道cmake应该是跨平台的。但有时它用于仅在Linux上运行的项目。

我可以将rpm硬编码为include和/usr/include作为库目录,但在Ubuntu系统上至少有两个可以包含这些文件的“标准”位置,不提及非标准路径,如/usr/lib/x86_64-linux-gnu中的路径。

1 个答案:

答案 0 :(得分:0)

我找到了以下cmake文件amirgholami's Github。到目前为止它对我有用。

#######################################################################
#
#  This is a basic, generic find_package function intended to find
#  any package with the following conditions:
#
#  (1) The package has a CMake variable associated with it
#      that is a path directory pointing to the installation directory
#      of the package.  It is assumed that the libraries and include
#      files are either contiained within this directory or the
#      sub-directories lib/ or include/, respectively.
#
#  (2) The name(s) of the required library file(s) will be given to
#      the macro as a string list argument, and each will be tested in 
#      sequence.
#
#  (3) The name(s) of the required include file(s) will be given to 
#      the macro as a string list argument, and each will be tested in 
#      sequence.
#
#  (4) For a package with associated environment variable VAR, this
#      macro will define the variables:
#
#        VAR_FOUND - Boolean indicating if all files/libraries were found
#        VAR_INCLUDE_DIRS - Directory path(s) to include files
#        VAR_LIBRARIES - Full path(s) to each libraries
#
# AUTHOR:  Kevin Paul <kpaul@ucar.edu>
# DATE:    11 Feb 2014
#   
#######################################################################

function(BASIC_FIND PCKG REQ_INCS REQ_LIBS)

#If environment variable ${PCKG}_DIR is specified, 
# it has same effect as local ${PCKG}_DIR
if( (NOT ${PCKG}_DIR) AND DEFINED ENV{${PCKG}_DIR} )
  set( ${PCKG}_DIR "$ENV{${PCKG}_DIR}" )
  message(STATUS " ${PCKG}_DIR is set from environment: ${${PCKG}_DIR}")
endif()

if (NOT ${PCKG}_DIR)
  if(!${PCKG}_FIND_QUIETLY)
    message (WARNING " Option ${PCKG}_DIR not set.")
  endif ()
else (NOT ${PCKG}_DIR)
  message (STATUS " ${PCKG}_DIR set to ${${PCKG}_DIR}")
endif (NOT ${PCKG}_DIR)

message (STATUS " Searching for package ${PCKG}...")
set (${PCKG}_FOUND FALSE PARENT_SCOPE)

# Look for each required include file
foreach(INC_FILE ${REQ_INCS})
  message (STATUS " Searching for include file: ${INC_FILE}")
  set (INC_DIR ${INC_FILE}-NOTFOUND)
  find_path(INC_DIR ${INC_FILE}
    HINTS ${${PCKG}_DIR} ${${PCKG}_DIR}/include)
  if (EXISTS ${INC_DIR}/${INC_FILE})
    message (STATUS " Found include file ${INC_FILE} in ${INC_DIR} required by ${PCKG}")
    set (${PCKG}_INCLUDE_DIRS ${${PCKG}_INCLUDE_DIRS} ${INC_DIR} PARENT_SCOPE)
  elseif(!${PCKG}_FIND_QUIETLY)
    message (WARNING " Failed to find include file ${INC_FILE} required by ${PCKG}")
  endif ()
endforeach()
# Look for each required library
foreach(LIB_NAME ${REQ_LIBS})
  message (STATUS " Searching for library: ${LIB_NAME}")
  set (LIB ${LIB_NAME}-NOTFOUND)
  find_library(LIB NAMES "lib${LIB_NAME}.a" "${LIB_NAME}"
    HINTS ${${PCKG}_DIR} ${${PCKG}_DIR}/lib)
  if (EXISTS ${LIB})
    message (STATUS " Found library at ${LIB} required by ${PCKG}")
    set (${PCKG}_LIBRARIES ${${PCKG}_LIBRARIES} ${LIB} PARENT_SCOPE)
    set (${PCKG}_FOUND TRUE PARENT_SCOPE)
    set (${PCKG}_FOUND TRUE )
  else ()
    set (${PCKG}_FOUND FALSE PARENT_SCOPE)
    set (${PCKG}_FOUND FALSE )
  endif ()
endforeach()

# If we made it this far, then we call the package "FOUND"
if(${PCKG}_FOUND)
  message (STATUS "All required include files and libraries found.")
else()
  if(!${PCKG}_FIND_QUIETLY)
    message ("WARNING! ${PCKG} not found.")
  else()
    message ("${PCKG} not found (Optional, Not Required).")
  endif()
endif()

endfunction(BASIC_FIND)

您在CMakeLists.txt(例如libpnetcdf-dev)中使用此方法:

include(basicFind)
BASIC_FIND (PNETCDF "pnetcdf.h" "pnetcdf")