KDevelop4:使用 cmake 设置项目

发布于 2024-10-31 00:11:01 字数 338 浏览 4 评论 0原文

我正在使用 Kdevelop4,并且想使用默认的 CMake c++ 项目。

我的计划是将我的应用程序划分为程序、几个共享库,并且我希望有一个单独的项目构建单元测试(我计划使用谷歌测试)。

我有几个问题:

  1. 如何修改默认的 cmake 文件以获得共享库,而不是可执行文件?
  2. 如何将google测试框架与cmake集成?

KDevelop4 生成的默认 CMakeLists.txt 看起来像这样:

project(kdevbook)

add_executable(kdevbook main.cpp)

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 :

  1. How to modify default cmake file in order to get a shared library, and not an executable file?
  2. 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽月 2024-11-07 00:11:01

1) 对于共享库:

add_library(kdevbooklib SHARED source.cpp)

更多信息。

2) 链接。

更新:

根 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)

库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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文