KDevelop4 : Setting up a project using cmake
I am using Kdevelop4, and would like to use a default CMake c++ project.
My plan is to partition my application into programs, several shared libraries, and I would like to have a separate project building unit tests (I am planing to use google test).
I have several questions :
-
开发者_JS百科
- How to modify default cmake file in order to get a shared library, and not an executable file?
- How to integrate google testing framework with cmake?
The default CMakeLists.txt produced by KDevelop4 looks something like this :
project(kdevbook)
add_executable(kdevbook main.cpp)
1) For shared library:
add_library(kdevbooklib SHARED source.cpp)
More info.
2) Link.
Update:
Root CMakeList.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
PROJECT(MyGreatProject)
SET(LIBRARY_OUTPUT_PATH ${MyGreatProject_BINARY_DIR}/bin CACHE PATH
"Single output directory for building all libraries.")
SET(EXECUTABLE_OUTPUT_PATH ${MyGreatProject_BINARY_DIR}/bin CACHE PATH
"Single output directory for building all executables.")
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
ADD_SUBDIRECTORY(MyGreatProjectLib)
ADD_SUBDIRECTORY(MyGreatProjectBin)
Libs MyGreatProjectLib/CMakeLists.txt:
PROJECT(MyGreatProjectLib)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})
add_library(MyGreatProjectLib SHARED source.cpp)
Bin MyGreatProjectBin/CMakeLists.txt
PROJECT(MyGreatProjectBin)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${MyGreatProjectLib_SOURCE_DIR})
add_executable(MyGreatProjectBin main.cpp)
target_link_libraries(MyGreatProjectBin MyGreatProjectLib)
精彩评论