AlgebraMaster

Modern C++ 创造非凡 . 改变世界

导航

CMake的一些正确姿势

0,设置Debug / Release:

CMakeLists.txt:

SET(CMAKE_BUILD_TYPE "Debug”)
or
SET(CMAKE_BUILD_TYPE "Release")

用参数设置

mkdir Release  
cd Release  
cmake -DCMAKE_BUILD_TYPE=Release ..  
make  

mkdir Debug  
cd Debug  
cmake -DCMAKE_BUILD_TYPE=Debug ..  
make  

 

 

 

1,output data file position

 

 

 

2020/1/21 分析VS2019的CMAKE过程

 

1> 已为配置“x64-Debug”启动 CMake 生成。
1> 命令行: "cmd.exe" /c ""D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  
-G
"Ninja"
-DCMAKE_INSTALL_PREFIX:PATH=
"D:\plugin_dev\cpp\cpp_test\CMake_VS\CMakeVS_01\out\install\x64-Debug"
-DCMAKE_CXX_COMPILER:FILEPATH=
"D:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe"
-DCMAKE_C_COMPILER:FILEPATH=
"D:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe"
-DCMAKE_BUILD_TYPE=
"Debug"
-DCMAKE_MAKE_PROGRAM=
"D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe"
"D:\plugin_dev\cpp\cpp_test\CMake_VS\CMakeVS_01" 2>&1" 1> 工作目录: D:\plugin_dev\cpp\cpp_test\CMake_VS\CMakeVS_01\out\build\x64-Debug 1> [CMake] -- The C compiler identification is MSVC 19.24.28315.0 1> [CMake] -- The CXX compiler identification is MSVC 19.24.28315.0 1> [CMake] -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe 1> [CMake] -- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe -- works 1> [CMake] -- Detecting C compiler ABI info 1> [CMake] -- Detecting C compiler ABI info - done 1> [CMake] -- Detecting C compile features 1> [CMake] -- Detecting C compile features - done 1> [CMake] -- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe 1> [CMake] -- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe -- works 1> [CMake] -- Detecting CXX compiler ABI info 1> [CMake] -- Detecting CXX compiler ABI info - done 1> [CMake] -- Detecting CXX compile features 1> [CMake] -- Detecting CXX compile features - done 1> [CMake] -- Configuring done 1> [CMake] -- Generating done 1> [CMake] -- Build files have been written to: D:/plugin_dev/cpp/cpp_test/CMake_VS/CMakeVS_01/out/build/x64-Debug 1> [CMake] 1> 已提取包含路径。 1> 已提取 CMake 变量。 1> 已提取源文件和标头。 1> 已提取代码模型。 1> CMake 生成完毕。

上面的一定是Naja Makefile.竟然不是NMake......

 

 

所以要在别的编辑器上例如Qt IDE:

 

 QT Ide认 编译器 的方法是在一个Bat文件,这个bat会设置环境变量,应该是从这里面解析的:

 

CLION就比较智能:

 

OPENGL+ASSIMP

cmake_minimum_required(VERSION 3.5)

project(Triangle)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# OPENGL
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})

if(NOT OPENGL_FOUND)
    message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)

# GLEW
set(GLEW_HOME D:/plugin_dev/libs/glew-2.1.0)
include_directories(${GLEW_HOME}/include)
link_directories(${GLEW_HOME}/lib/Release/x64)

# GLFW
set(GLFW_HOME D:/plugin_dev/libs/glfw-3.3.1.bin.WIN64)
include_directories(${GLFW_HOME}/include/)
link_directories(${GLFW_HOME}/lib-vc2019)

# STB
include_directories(D:/plugin_dev/libs/stb)

# GLM
include_directories(D:/plugin_dev/libs/GLM_include)

# Assimp
include_directories(D:/plugin_dev/libs/assimp-5.0.1_bin/win_vs2019/include)

if(CMAKE_BUILD_TYPE STREQUAL Debug)
    message(">> Cmake will use debug mode to link debug lib")
    link_directories(D:/plugin_dev/libs/assimp-5.0.1_bin/win_vs2019/Debug) # we first link the debug
    link_libraries(assimp-vc142-mtd)
else()
    link_directories(D:/plugin_dev/libs/assimp-5.0.1_bin/win_vs2019/Release) # we first link the debug
    link_libraries(assimp-vc142-mt)
endif()


# output excutable dir
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})


# SRC FILE
FILE(
    GLOB
    SRC
    *.cpp *.h
    )

add_executable(Triangle ${SRC})
target_link_libraries(Triangle glew32s glfw3 opengl32 )

 

posted on 2017-08-26 14:04  gearslogy  阅读(540)  评论(0编辑  收藏  举报