0

I want to create a CMakeLists that outputs two versions of my executable. One is going to be a release version of my C app. The other is the gtest version of my app.

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

How do I make it so that the first exe doesn't require the google library and how do I give specific gcc options for c++ to the gtest version?

Bluebaron
  • 2,289
  • 2
  • 27
  • 37

1 Answers1

1

you should create a library first and then link both, the executable and the test, with it. The executable and the test should have a separate source code though.

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)
Jana
  • 5,516
  • 5
  • 23
  • 29
  • How do I specify different compiler directives for each library and executable? Also how do I make sure that my main executable doesn't compile with the STL? – Bluebaron Aug 07 '15 at 17:10
  • use COMPILE_FLAGS with set_target_properties: http://stackoverflow.com/questions/5096881/does-set-target-properties-in-cmake-override-cmake-cxx-flags – Jana Aug 07 '15 at 17:31