CMake C ++编译命令

时间:2019-07-14 05:04:53

标签: c++ cmake

我目前正在学习CMake,我知道它是构建文件生成器,我想查看CMake正在运行的确切命令,用于编译和链接我的C ++文件。例如,如果我正在处理单个文件main.cpp,并且要使用gcc进行编译,则可以运行gcc -o main main.cpp。我将如何查看CMake正在运行的C ++命令?我尝试过make VERBOSE=1,但这只显示了与CMake相关的命令,而不是C ++编译器命令。

// main.cpp
#include <iostream>

int main()
{
    std::cout << "Hello world" << std::endl;
}

//CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
project(example LANGUAGES CXX)
add_executable(main main.cpp)

这将创建一个包含以下内容的Makefile:

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.14

# Default target executed when no arguments are given to make.
default_target: all

.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/local/Cellar/cmake/3.14.5/bin/cmake

# The command to remove a file.
RM = /usr/local/Cellar/cmake/3.14.5/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /Users/.../Desktop/cpp

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /Users/.../Desktop/cpp/build

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target rebuild_cache
rebuild_cache:
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
    /usr/local/Cellar/cmake/3.14.5/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# Special rule for the target edit_cache
edit_cache:
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
    /usr/local/Cellar/cmake/3.14.5/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

# The main all target
all: cmake_check_build_system
    $(CMAKE_COMMAND) -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles /Users/.../Desktop/cpp/build/CMakeFiles/progress.marks
    $(MAKE) -f CMakeFiles/Makefile2 all
    $(CMAKE_COMMAND) -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
    $(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
    $(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
    $(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
    $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named main

# Build rule for target.
main: cmake_check_build_system
    $(MAKE) -f CMakeFiles/Makefile2 main
.PHONY : main

# fast build rule for target.
main/fast:
    $(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
.PHONY : main/fast

main.o: main.cpp.o

.PHONY : main.o

# target to build an object file
main.cpp.o:
    $(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/main.cpp.o
.PHONY : main.cpp.o

main.i: main.cpp.i

.PHONY : main.i

# target to preprocess a source file
main.cpp.i:
    $(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/main.cpp.i
.PHONY : main.cpp.i

main.s: main.cpp.s

.PHONY : main.s

# target to generate assembly for a file
main.cpp.s:
    $(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/main.cpp.s
.PHONY : main.cpp.s

# Help Target
help:
    @echo "The following are some of the valid targets for this Makefile:"
    @echo "... all (the default if no target is provided)"
    @echo "... clean"
    @echo "... depend"
    @echo "... rebuild_cache"
    @echo "... edit_cache"
    @echo "... main"
    @echo "... main.o"
    @echo "... main.i"
    @echo "... main.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
    $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

make VERBOSE=1返回:

/usr/local/Cellar/cmake/3.14.5/bin/cmake -S/Users/.../Desktop/cpp -B/Users/.../Desktop/cpp/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles /Users/.../Desktop/cpp/build/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
cd /Users/.../Desktop/cpp/build && /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_depends "Unix Makefiles" /Users/.../Desktop/cpp /Users/.../Desktop/cpp /Users/.../Desktop/cpp/build /Users/.../Desktop/cpp/build /Users/.../Desktop/cpp/build/CMakeFiles/main.dir/DependInfo.cmake --color=
Dependee "/Users/.../Desktop/cpp/build/CMakeFiles/main.dir/DependInfo.cmake" is newer than depender "/Users/.../Desktop/cpp/build/CMakeFiles/main.dir/depend.internal".
Dependee "/Users/.../Desktop/cpp/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/.../Desktop/cpp/build/CMakeFiles/main.dir/depend.internal".
Scanning dependencies of target main
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++    -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk   -o CMakeFiles/main.dir/main.cpp.o -c /Users/.../Desktop/cpp/main.cpp
[100%] Linking CXX executable main
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/main.dir/main.cpp.o  -o main
[100%] Built target main
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles 0

0 个答案:

没有答案