CMakeLists.txt文件写法(12):查找特定软件的安装目录

本文介绍如何使用CMake的FIND_PATH命令来定位WxWidgets库的安装位置及其特征文件,通过设置变量和路径来确保项目能够正确地链接到所需的库文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

例如:

#Wx可能安装的目录(注意斜线的方向)
SET(DirectorOfWxMyBe   c:/
        d:/
        c:/wx
        d:/wx)

#能代表WxWindows特征的文件
SET(CharacteristicFilesOfWx  aclocal.m4
        autoconf_inc.m4
        autogen.sh
        BuildCVS.txt
        config.guess
        config.sub
        configure
        configure.in
        install-cocoa.txt
        install-dfb.txt
        install-gtk.txt
        install-mac.txt
        install-mgl.txt
        install-motif.txt
        INSTALL-MSW.txt
        INSTALL-OS2.txt
        install-sh
        install-x11.txt
        Makefile.in
        mkinstalldirs
        readme-cocoa.txt
        readme-gtk.txt
        readme-mac.txt
        readme-mgl.txt
        readme-motif.txt
        README-MSW.txt
        readme-x11.txt
        regen
        setup.h.in
        version-script.in
        wx-config-inplace.in
        wx-config.in
        wxBase.spec
        wxGTK.spec
        wxMGL.spec
        wxMotif.spec
        wxwin.m4
        wxX11.spec)

#WxWindows的安装目录        
FIND_PATH(WxRoot NAMES ${CharacteristicFilesOfWx} PATHS ${DirectorOfWxMyBe})

MESSAGE(${WxRoot})

 

 FIND_PATH: Find the directory containing a file.

   FIND_PATH(<VAR> name1 path1 path2 ...)

This is the short-hand signature for the command that is sufficient in many cases. It is the same as FIND_PATH(<VAR> name1 PATHS path2 path2 ...)

   FIND_PATH(
<VAR>
name | NAMES name1 [name2 ...]
PATHS path1 [path2 ... ENV var]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[DOC "cache documentation string"]
[NO_DEFAULT_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_CMAKE_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
[NO_CMAKE_SYSTEM_PATH]
)

This command is used to find a directory containing the named file. A cache entry named by <VAR> is created to store the result of this command. If the file in a directory is found the result is stored in the variable and the search will not be repeated unless the variable is cleared. If nothing is found, the result will be <VAR>-NOTFOUND, and the search will be attempted again the next time FIND_PATH is invoked with the same variable. The name of the file in a directory that is searched for is specified by the names listed after the NAMES argument. Additional search locations can be specified after the PATHS argument. If ENV var is found in the PATHS section the environment variable var will be read and converted from a system environment variable to a cmake style list of paths. For example ENV PATH would be a way to list the system path variable. The argument after DOC will be used for the documentation string in the cache. PATH_SUFFIXES can be used to give sub directories that will be appended to the search paths.

If NO_DEFAULT_PATH is specified, then no additional paths are added to the search. If NO_DEFAULT_PATH is not specified, the search process is as follows:

1. Search cmake specific environment variables. This can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.

   CMAKE_FRAMEWORK_PATH
CMAKE_APPBUNDLE_PATH
CMAKE_INCLUDE_PATH

2. Search cmake variables with the same names as the cmake specific environment variables. These are intended to be used on the command line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is passed.

   CMAKE_FRAMEWORK_PATH
CMAKE_APPBUNDLE_PATH
CMAKE_INCLUDE_PATH

3. Search the standard system environment variables. This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.

   PATH
INCLUDE

4. Search cmake variables defined in the Platform files for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is passed.

   CMAKE_SYSTEM_FRAMEWORK_PATH
CMAKE_SYSTEM_APPBUNDLE_PATH
CMAKE_SYSTEM_INCLUDE_PATH

5. Search the paths specified after PATHS or in the short-hand version of the command.

On Darwin or systems supporting OSX Frameworks, the cmake variable CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:

   "FIRST"  - Try to find frameworks before standard
libraries or headers. This is the default on Darwin.
"LAST" - Try to find frameworks after standard
libraries or headers.
"ONLY" - Only try to find frameworks.
"NEVER". - Never try to find frameworks.

On Darwin or systems supporting OSX Application Bundles, the cmake variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the following:

   "FIRST"  - Try to find application bundles before standard
programs. This is the default on Darwin.
"LAST" - Try to find application bundles after standard
programs.
"ONLY" - Only try to find application bundles.
"NEVER". - Never try to find application bundles.

The reason the paths listed in the call to the command are searched last is that most users of CMake would expect things to be found first in the locations specified by their environment. Projects may override this behavior by simply calling the command twice:

   FIND_PATH(<VAR> NAMES name PATHS paths NO_DEFAULT_PATH)
FIND_PATH(<VAR> NAMES name)

Once one of these calls succeeds the result variable will be set and stored in the cache so that neither call will search again.

When searching for frameworks, if the file is specified as A/b.h, then the framework search will look for A.framework/Headers/b.h. If that is found the path will be set to the path to the framework. CMake will convert this to the correct -F option to include the file.

Make Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. -- The C compiler identification is GNU 7.5.0 -- The CXX compiler identification is GNU 7.5.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done Build type: Release -- Performing Test COMPILER_SUPPORTS_CXX11 -- Performing Test COMPILER_SUPPORTS_CXX11 - Success -- Performing Test COMPILER_SUPPORTS_CXX0X -- Performing Test COMPILER_SUPPORTS_CXX0X - Success -- Using flag -std=c++11. -- Found OpenCV: /usr/local (found suitable version "4.2.0", minimum required is "4.2") OPENCV VERSION: 4.2.0 CMake Warning at CMakeLists.txt:43 (find_package): By not providing "Findrealsense2.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "realsense2", but CMake did not find one. Could not find a package configuration file provided by "realsense2" with any of the following names: realsense2Config.cmake realsense2-config.cmake Add the installation prefix of "realsense2" to CMAKE_PREFIX_PATH or set "realsense2_DIR" to a directory containing one of the above files. If "realsense2" provides a separate development package or SDK, be sure it has been installed. CMake Error at CMakeLists.txt:116 (add_subdirectory): add_subdirectory given source "Thirdparty/g2o" which is not an existing directory. -- Configuring incomplete, errors occurred! See also "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log". make: *** 没有指明目标并且找不到 makefile。 停止。 ./build.sh: 第 9 行: cd: ../../g2o: 没有那个文件目录 Configuring and building Thirdparty/g2o ... CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. Build type: Release -- Using flag -std=c++11. OPENCV VERSION: 4.2.0 CMake Warning at CMakeLists.txt:43 (find_package): By not providing "Findrealsense2.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "realsense2", but CMake did not find one. Could not find a package configuration file provided by "realsense2" with any of the following names: realsense2Config.cmake realsense2-config.cmake Add the installation prefix of "realsense2" to CMAKE_PREFIX_PATH or set "realsense2_DIR" to a directory containing one of the above files. If "realsense2" provides a separate development package or SDK, be sure it has been installed. CMake Error at CMakeLists.txt:116 (add_subdirectory): add_subdirectory given source "Thirdparty/g2o" which is not an existing directory. -- Configuring incomplete, errors occurred! See also "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log". make: *** 没有指明目标并且找不到 makefile。 停止。 ./build.sh: 第 18 行: cd: ../../Sophus: 没有那个文件目录 Configuring and building Thirdparty/Sophus ... CMake Error: The source directory "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/build" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI. make: *** 没有指明目标并且找不到 makefile。 停止。 Uncompress vocabulary ... Configuring and building ORB_SLAM3 ... mkdir: 无法创建目录"build": 文件已存在 CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. Build type: Release -- Using flag -std=c++11. OPENCV VERSION: 4.2.0 CMake Warning at CMakeLists.txt:43 (find_package): By not providing "Findrealsense2.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "realsense2", but CMake did not find one. Could not find a package configuration file provided by "realsense2" with any of the following names: realsense2Config.cmake realsense2-config.cmake Add the installation prefix of "realsense2" to CMAKE_PREFIX_PATH or set "realsense2_DIR" to a directory containing one of the above files. If "realsense2" provides a separate development package or SDK, be sure it has been installed. CMake Error at CMakeLists.txt:116 (add_subdirectory): add_subdirectory given source "Thirdparty/g2o" which is not an existing directory. -- Configuring incomplete, errors occurred! See also "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log". make: *** 没有指明目标并且找不到 makefile。 停止。
最新发布
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值