簡體   English   中英

帶有gtest的CMakeLists C程序(C ++)

[英]CMakeLists C program with gtest(C++)

我想創建一個CMakeLists,它輸出我的可執行文件的兩個版本。 一個將是我的C應用程序的發行版。 另一個是我的應用程序的gtest版本。

cmake_minimum_required(VERSION 3.1)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "C:\\Users\\James\\ClionProjects\\DustAgent\\build")

project(DustAgent)

include_directories ( WindowsApi gtest-1.7.0/include )

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -pthread")

set(SOURCE_FILES main.c utilities/utilities.c utf8/utf8.c)
set(GTEST_SOURCE_FILES ${SOURCE_FILES} gtest-1.7.0/src/gtest-all.cc)
add_executable(DustAgent ${SOURCE_FILES})

如何使第一個exe不需要google庫,以及如何為gtest版本的c ++提供特定的gcc選項?

您應該先創建一個庫,然后將可執行文件和測試都鏈接到該庫。 可執行文件和測試應具有單獨的源代碼。

add_library(DustAgentLibrary utilities/utilities.c utf8/utf8.c)

add_executable(DustAgent main.c)
target_link_libraries(DustAgent DustAgentLibrary)

add_executable(DustAgentTest test.c)
target_link_libraries(DustAgentTest DustAgentLibrary gtest)
add_test(DustAgentTest DustAgentTest)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM