Cmake 脚本对项目输出路径和输出头文件的路径定义

对Lib项目的统一输出路径以下时解决方案:

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Bin)

 

以上三行命令要写在根(root)CmakeLists.txt的里面.

 

Reference:

http://*.com/questions/3702115/creating-a-directory-in-cmake

http://*.com/questions/3742090/custom-directory-for-cmake-library-output

 

http://*.com/questions/17653738/recursive-cmake-search-for-header-and-source-files

 http://*.com/questions/6594796/how-do-i-make-cmake-output-into-a-bin-dir

 

 

项目依赖的头文件的输出路径:

References:

http://*.com/questions/5668397/cmake-export-third-party-headers-to-directory

 

http://*.com/questions/697560/how-to-copy-directory-from-source-tree-to-binary-tree

http://*.com/questions/10487256/cmake-how-to-properly-copy-static-librarys-header-file-into-usr-include

 

 以下是(root)CmakeLists.txt的代码:

Cmake 脚本对项目输出路径和输出头文件的路径定义
 1 cmake_minimum_required(VERSION 2.8)
 2 
 3 #set(CMAKE_C_COMPILER "D:\VS2008Release\VC\bin\amd64")
 4 #set(CMAKE_CXX_COMPILER "D:\VS2008Release\VC\bin\amd64")
 5 
 6 PROJECT(ImageMagick) 
 7 
 8 #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lib)
 9 #set(ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Lib")
10 #message(STATUS ${CMAKE_BINARY_DIR})
11 
12 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lib)
13 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lib)
14 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Bin)
15 
16 #set(SHARE_LIBS_DIR ${CMAKE_BINARY_DIR}/Lib)
17 
18 add_subdirectory(bzlib) 
19 add_subdirectory(cairo)
20 add_subdirectory(coders)
21 add_subdirectory(croco)
22 add_subdirectory(ffi)
23 add_subdirectory(filters)
24 add_subdirectory(glib)
25 add_subdirectory(jbig)
26 add_subdirectory(jp2)
27 add_subdirectory(jpeg)
28 add_subdirectory(lcms)
29 add_subdirectory(librsvg)
30 add_subdirectory(libxml)
31 add_subdirectory(lqr)
32 add_subdirectory(magick)
33 add_subdirectory(Magick++)
34 add_subdirectory(pango)
35 add_subdirectory(pixman)
36 add_subdirectory(png)
37 add_subdirectory(tiff)
38 add_subdirectory(ttf)
39 add_subdirectory(wand)
40 add_subdirectory(webp)
41 add_subdirectory(wmf)
42 add_subdirectory(zlib)
43 
44 #头文件输出
45 file(COPY  "${CMAKE_BINARY_DIR}/Magick++/lib/Magick++.h"  
46 DESTINATION  "${CMAKE_BINARY_DIR}/include"  )
47 
48 #wand文件夹
49 
50 file(GLOB wand_hdrs "${CMAKE_BINARY_DIR}/wand/*.h")
51 file(COPY  ${wand_hdrs}  
52 DESTINATION  "${CMAKE_BINARY_DIR}/include/wand"  )
53 
54 
55 file(COPY  "${CMAKE_BINARY_DIR}/VisualMagick/wand/wand-config.h.in"  
56 DESTINATION  "${CMAKE_BINARY_DIR}/include/wand"  )
57 #文件重命名
58 file(RENAME "${CMAKE_BINARY_DIR}/include/wand/wand-config.h.in" "${CMAKE_BINARY_DIR}/include/wand/wand-config.h")
59 
60 
61 
62 
63 #Magick++文件夹
64 file(GLOB Magick_hdrs "${CMAKE_BINARY_DIR}/Magick++/lib/Magick++/*.h")
65 file(COPY  ${Magick_hdrs}  
66 DESTINATION  "${CMAKE_BINARY_DIR}/include/Magick++"  )
67 
68 #magick文件夹
69 file(GLOB magick_hdrs "${CMAKE_BINARY_DIR}/magick/*.h")
70 file(COPY ${magick_hdrs}
71 DESTINATION  "${CMAKE_BINARY_DIR}/include/magick"  
72 )
73 
74 #wand
75 #add_subdirectory(cairo)
View Code

TIPS:add_subdirectory命令执行中,就直接执行子目录下的CmakeLists.txt里面的代码了

Cmake 脚本对项目输出路径和输出头文件的路径定义

上一篇:ios模拟器未能安装此应用程序


下一篇:《软件架构实践》读书笔记1构架商业周期