[cmake] Windows の cmake で make install を実行すると、指定されたディレクトリにインストールされます。

問題: チュートリアルのほとんどは uinx の下にあり、cmake ファイル INSTALL がインストールされています。ただし、デフォルトのパス接頭辞も Unix っぽいためです。

INSTALL(FILES COPYRIGHT README DESTINATION share/doc/cmake/)

DESTINATION、インストール ファイルへのパスは実際には /usr/local/share/doc/cmake/ です。

しかし、ウィンドウの下にはそのようなパスはありません。したがって、デフォルトのパス接頭辞を変更します。

解決:

一般的な手順 (Linux の場合):

mkdir build && cd build
cmake ..
make
make install

1. 初期ファイルツリー

PS D:\Code\cmaketest\cmake_test03> tree /F
卷 Data 的文件夹 PATH 列表
卷序列号为 6E99-8D8D
D:.
│  CMakeLists.txt
│  COPYRIGHT
│  README
│  runhello.sh
│
├─build
├─doc
│      hello.txt
│
└─src
        CMakeLists.txt
        main.cpp

2. cd .\build\ に切り替えます。

PS D:\Code\cmaketest\cmake_test03> cd .\build\

3. cmake 入力 cmake -S ../ -B ./ -G "MinGW Makefiles"

PS D:\Code\cmaketest\cmake_test03\build> cmake -S ../ -B ./ -G "MinGW Makefiles"
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw64/bin/gcc.exe - 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: C:/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.18)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: D:/Code/cmaketest/cmake_test03/build

4.cmake は、デフォルトのインストール パスのプレフィックスを変更します重要なステップ

入力cmake -DCMAKE_INSTALL_PREFIX= D:\cmakeinstalltest\ -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -G"MinGW Makefiles" ../

参考: [CMake] cmake install command_Yngz_Miao のブログ - CSDN blog_cmake install

PS D:\Code\cmaketest\cmake_test03\build> cmake -DCMAKE_INSTALL_PREFIX=D:\cmakeinstalltest\ -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -G"MinGW Makefiles" ../
CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.18)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: D:/Code/cmaketest/cmake_test03/build

5.メイク入力メイク

PS D:\Code\cmaketest\cmake_test03\build> make
Scanning dependencies of target hello
[ 50%] Building CXX object bin/CMakeFiles/hello.dir/main.obj
[100%] Linking CXX executable hello.exe
[100%] Built target hello

6. インストールは成功しました

PS D:\Code\cmaketest\cmake_test03\build> make install
[100%] Built target hello
Install the project...
-- Install configuration: ""
-- Installing: D:/cmakeinstalltest/share/doc/cmake/COPYRIGHT
-- Installing: D:/cmakeinstalltest/share/doc/cmake/README
-- Installing: D:/cmakeinstalltest/bin/runhello.sh
-- Up-to-date: D:/cmakeinstalltest/share/doc/cmake/
-- Installing: D:/cmakeinstalltest/share/doc/cmake//hello.txt

7. 結果。スクリプトはここにインストールされます (txt ファイル)

PS D:\cmakeinstalltest> tree /F
卷 Data 的文件夹 PATH 列表
卷序列号为 6E99-8D8D
D:.
├─bin
│      runhello.sh
│
└─share
    └─doc
        └─cmake
                COPYRIGHT
                hello.txt
                README

添付ファイル: プロジェクトの下の CMakeLists コンテンツ

PROJECT(HELLO)
ADD_SUBDIRECTORY(src bin)
#cmake -DCMAKE_INSTALL_PREFIX=D:\CloudMusic\ -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -G"MinGW Makefiles" ../
INSTALL(FILES COPYRIGHT README DESTINATION share/doc/cmake/)
INSTALL(PROGRAMS runhello.sh DESTINATION bin)
INSTALL(DIRECTORY doc/ DESTINATION share/doc/cmake/)

 

 

 

おすすめ

転載: blog.csdn.net/m0_57168310/article/details/126338451