CMakeList.txt Demo

动态库:

PROJECT(ProjectName)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
#add_compile_definitions(BOOST_WINDOWS)
#add_compile_definitions(__BUILD_IN_MSYS2)
add_definitions(-D __BUILD_IN_MSYS2)
add_definitions(-D BOOST_LOG_DYN_LINK)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
SET(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
#set(HEADER_FILES /c/msys64/mingw64/x86_64-w64-mingw32/include/pthread.h)
#INCLUDE_DIRECTORIES("/c/msys64/mingw64/include")
#INCLUDE_DIRECTORIES("/d/code/ProjectName")
INCLUDE_DIRECTORIES("../Base")
INCLUDE_DIRECTORIES("/usr/include/mysql-cppconn/jdbc/")
#LINK_DIRECTORIES(/d/code/Base)
#LINK_DIRECTORIES(/c/msys64/mingw64/lib)
LINK_DIRECTORIES(../Image/Image)
LINK_DIRECTORIES(/usr/local/lib)
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
AUX_SOURCE_DIRECTORY(../Base DIR_SRCS_BASE)
list(REMOVE_ITEM DIR_SRCS "Logger.h")
list(REMOVE_ITEM DIR_SRCS "Logger.cpp")
ADD_LIBRARY(ProjectName SHARED ${DIR_SRCS_BASE} ${DIR_SRCS_SCENE} ${DIR_SRCS_SCENE_DB} ${DIR_SRCS})
#TARGET_LINK_LIBRARIES(ProjectName Scene)
#TARGET_LINK_LIBRARIES(ProjectName Base)
TARGET_LINK_LIBRARIES(ProjectName Image)
TARGET_LINK_LIBRARIES(ProjectName boost_date_time)
TARGET_LINK_LIBRARIES(ProjectName boost_filesystem)
TARGET_LINK_LIBRARIES(ProjectName boost_iostreams)
TARGET_LINK_LIBRARIES(ProjectName boost_locale)
TARGET_LINK_LIBRARIES(ProjectName boost_log_setup)
TARGET_LINK_LIBRARIES(ProjectName boost_log)
TARGET_LINK_LIBRARIES(ProjectName boost_thread)
TARGET_LINK_LIBRARIES(ProjectName pthread)
TARGET_LINK_LIBRARIES(ProjectName z)
TARGET_LINK_LIBRARIES(ProjectName mysqlcppconn)
TARGET_LINK_LIBRARIES(ProjectName stdc++)

动态库:

PROJECT(Image)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
add_definitions(-D __BUILD_IN_MSYS2)
#add_compile_definitions(BOOST_WINDOWS)
add_definitions(-D IMAGE_EXPORTS)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
SET(CMAKE_CXX_FLAGS "-std=c++0x")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )
#set(HEADER_FILES /c/msys64/mingw64/x86_64-w64-mingw32/include/pthread.h)
#INCLUDE_DIRECTORIES("/c/msys64/mingw64/include")
INCLUDE_DIRECTORIES("/root/poco-poco-1.8.1-release/Foundation/include")
INCLUDE_DIRECTORIES("../jpeg")
INCLUDE_DIRECTORIES("../png")
INCLUDE_DIRECTORIES("../zlib")
INCLUDE_DIRECTORIES("../RectangleBinPack")
INCLUDE_DIRECTORIES("../CxImage")
LINK_DIRECTORIES(../CxImage)
LINK_DIRECTORIES(../jpeg)
LINK_DIRECTORIES(../png)
LINK_DIRECTORIES(../zlib)
LINK_DIRECTORIES(../RectangleBinPack)
#LINK_DIRECTORIES(/c/msys64/mingw64/lib)
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
list(REMOVE_ITEM DIR_SRCS "Image.cpp")
ADD_LIBRARY(Image SHARED ${DIR_SRCS})
#set_property(TARGET Image PROPERTY POSITION_INDEPENDENT_CODE ON)
TARGET_LINK_LIBRARIES(Image CxImage)
TARGET_LINK_LIBRARIES(Image jpeg)
TARGET_LINK_LIBRARIES(Image png)
TARGET_LINK_LIBRARIES(Image zlib)
TARGET_LINK_LIBRARIES(Image RectangleBinPack)
TARGET_LINK_LIBRARIES(Image PocoFoundation)
TARGET_LINK_LIBRARIES(Image stdc++)

静态库:

PROJECT(CxImage)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
add_definitions(-D __BUILD_IN_MSYS2)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )
#set(HEADER_FILES /c/msys64/mingw64/x86_64-w64-mingw32/include/pthread.h)
#INCLUDE_DIRECTORIES("/c/msys64/mingw64/include")
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_LIBRARY(CxImage STATIC ${DIR_SRCS})

可执行程序:

PROJECT(Test)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
#add_compile_definitions(BOOST_WINDOWS)
#add_compile_definitions(__BUILD_IN_MSYS2)
add_definitions(-D __BUILD_IN_MSYS2)
add_definitions(-D BOOST_LOG_DYN_LINK)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
SET(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
#set(HEADER_FILES /c/msys64/mingw64/x86_64-w64-mingw32/include/pthread.h)
#INCLUDE_DIRECTORIES("/c/msys64/mingw64/include")
#INCLUDE_DIRECTORIES("../SceneBuilder")
#LINK_DIRECTORIES(/d/code/Base)
#LINK_DIRECTORIES(/d/code/Scene)
#LINK_DIRECTORIES(/c/msys64/mingw64/lib)
LINK_DIRECTORIES(../SceneBuilder)
LINK_DIRECTORIES(/usr/local/lib)
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
add_executable(Test ${DIR_SRCS})
TARGET_LINK_LIBRARIES(Test SceneBuilder)
TARGET_LINK_LIBRARIES(Test boost_date_time)
TARGET_LINK_LIBRARIES(Test boost_filesystem)
TARGET_LINK_LIBRARIES(Test boost_iostreams)
TARGET_LINK_LIBRARIES(Test boost_locale)
TARGET_LINK_LIBRARIES(Test boost_log_setup)
TARGET_LINK_LIBRARIES(Test boost_log)
TARGET_LINK_LIBRARIES(Test boost_thread)
TARGET_LINK_LIBRARIES(Test pthread)
TARGET_LINK_LIBRARIES(Test stdc++)

编译:

cd /root/ProjectSrc
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Release .
make

发表评论

电子邮件地址不会被公开。 必填项已用*标注

15 + 15 =