CMake:为库设置用户定义的路径
CMake: Set user-defined path for library
我正在使用 Windows,我想创建一个 CMakeLists.txt
以允许我构建 Qt 应用程序。
我已将 Qt 安装在 PATH
环境变量中不存在的文件夹中,我想在调用 CMake 时指定该文件夹。
我想创建一个变量,当我设置 Qt 库路径时,可以在从命令行和 gui 调用 CMake 时设置该变量。有了这个,我可以 运行 CMake 并使用存储在任何文件夹中的 Qt 编译项目。我该怎么做?
这是我的 CMakeFile:
cmake_minimum_required (VERSION 3.0)
project (myproject)
set (project_name myproject)
set (project_major_version 0)
set (project_minor_version 1)
set (project_fix_version 0)
set (project_version ${project_major_version}.${project_minor_version}.${project_fix_version})
set (output_dir "build")
# Source files
include_directories (${cmake_current_source_dir})
file (GLOB project_src "*.cpp")
# Project settings
set (cmake_automoc on)
find_package (qt5widgets)
add_executable (myproject ${project_src})
target_link_libraries (${project_name} qt5::widgets)
In order for find_package to be successful, Qt 5 must be found below
the CMAKE_PREFIX_PATH, or the Qt5<Module>_DIR must be set in the CMake
cache to the location of the Qt5WidgetsConfig.cmake file. The easiest
way to use CMake is to set the CMAKE_PREFIX_PATH environment variable
to the install prefix of Qt 5.
我正在使用 Windows,我想创建一个 CMakeLists.txt
以允许我构建 Qt 应用程序。
我已将 Qt 安装在 PATH
环境变量中不存在的文件夹中,我想在调用 CMake 时指定该文件夹。
我想创建一个变量,当我设置 Qt 库路径时,可以在从命令行和 gui 调用 CMake 时设置该变量。有了这个,我可以 运行 CMake 并使用存储在任何文件夹中的 Qt 编译项目。我该怎么做?
这是我的 CMakeFile:
cmake_minimum_required (VERSION 3.0)
project (myproject)
set (project_name myproject)
set (project_major_version 0)
set (project_minor_version 1)
set (project_fix_version 0)
set (project_version ${project_major_version}.${project_minor_version}.${project_fix_version})
set (output_dir "build")
# Source files
include_directories (${cmake_current_source_dir})
file (GLOB project_src "*.cpp")
# Project settings
set (cmake_automoc on)
find_package (qt5widgets)
add_executable (myproject ${project_src})
target_link_libraries (${project_name} qt5::widgets)
In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5<Module>_DIR must be set in the CMake cache to the location of the Qt5WidgetsConfig.cmake file. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.