Problem : Most of the tutorials are under uinx, and the cmake file INSTALL is installed. But because the default path prefix is also Unix-like.
INSTALL(FILES COPYRIGHT README DESTINATION share/doc/cmake/)
DESTINATION, the path to the installation file is actually /usr/local/share/doc/cmake/
But there is no such path under windows. So modify the default path prefix.
solve:
Common steps (under linux):
mkdir build && cd build
cmake ..
make
make install
1. The initial file tree
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. Switch to cd .\build\
PS D:\Code\cmaketest\cmake_test03> cd .\build\
3. cmake input 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 modifies the default installation path prefix . critical step
输入cmake -DCMAKE_INSTALL_PREFIX=D:\cmakeinstalltest\ -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -G"MinGW Makefiles" ../
Reference: [CMake] cmake install command_Yngz_Miao's blog-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. make input make
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. The installation is successful
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. Results. The script is installed here, txt file
PS D:\cmakeinstalltest> tree /F
卷 Data 的文件夹 PATH 列表
卷序列号为 6E99-8D8D
D:.
├─bin
│ runhello.sh
│
└─share
└─doc
└─cmake
COPYRIGHT
hello.txt
README
Attachment: CMakeLists content under the project
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/)