开发者

Cmake : on the findALSA.cmake example

In order to understand how to link libraries, someone advises me to look at the findALSA example which is :

find_path(ALSA_INCLUDE_DIR NAMES asoundlib.h
          PATH_SUFFIXES alsa
          DOC "The ALSA (asound) include directory"
)

find_library(ALSA_LIBRARY NAMES asound
          DOC "The ALSA (asound) library"
)

# handle the QUIETLY and REQUIRED arguments and set ALSA_FOUND to TRUE if 
# all listed variables are TRUE
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA DEFAULT_MSG ALSA_LIBRARY ALSA_INCLUDE_DIR)

if(ALSA_FOUND)
  set( ALSA_LIBRARIES ${ALSA_LIBRARY} )
  set( ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIR} )
endif()

mark_as_advanced(ALSA_INCLUDE_DIR ALSA_LIBRARY)

What I don't understand is :

if(ALSA_FOUND)
  set( ALSA_LIBRARIES ${ALSA_LIBRARY} )
  set( ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIR} )
endif()

Question 1 : Is that because ${ALSA_LIBRARY} and ${ALSA_INCLUDE_DIR} can only point to a single file / single directory ?

Question 2 : Can someone show me how to rewrite the example if I want to link 2 include directories and 2 library files ?

Let's say that we have the following example :

/alsa/dir1/asound1.h
/alsa/dir2/asound2.h
/alsa/lib/lib开发者_运维问答asound1.a
/alsa/lib/libasound2.a

Question 3 : in particular, what becomes the FIND_PACKAGE_HANDLE_STANDARD_ARGS command ?

Thank you very much


  1. Yes, ASLI_LIBRARIES will combine these.

2 & 3: Define in find_package_handle_standard_args only the things that are required for the package to work correctly. The code below is for when everything is required.

find_path(ALSA_INCLUDE_DIR1 NAMES asound1.h
          PATH_SUFFIXES alsa
          DOC "The ALSA (asound) include directory 1"
)

find_path(ALSA_INCLUDE_DIR2 NAMES asound2.h
          PATH_SUFFIXES alsa
          DOC "The ALSA (asound) include directory 2"
)

find_library(ALSA_LIBRARY2 NAMES asound1
          DOC "The ALSA (asound) library 1"
)

find_library(ALSA_LIBRARY2 NAMES asound2
          DOC "The ALSA (asound) library 2"
)

# handle the QUIETLY and REQUIRED arguments and set ALSA_FOUND to TRUE if 
# all listed variables are TRUE
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA DEFAULT_MSG ALSA_LIBRARY1 ALSA_LIBRARY2 ALSA_INCLUDE_DIR1 ALSA_INCLUDE_DIR2)

if(ALSA_FOUND)
  set( ALSA_LIBRARIES ${ALSA_LIBRARY1} ${ALSA_LIBRARY2} )
  set( ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIR1} ${ALSA_INCLUDE_DIR2} )
endif()

mark_as_advanced(ALSA_INCLUDE_DIR ALSA_LIBRARY)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜