0

I'm using rapidjson and I want to use std::string's with it. Then I have to define this -DRAPIDJSON_HAS_STDSTRING.

My CMakeLists.txt have now:

add_definitions(-DRAPIDJSON_HAS_STDSTRING)

And it builds ok.

The problem is that in Eclipse CDT I want the indexer to recognize that define. Then it will not mark some functions as errors.

How can I do it with CMakeLists.txt ? I tried this without luck:

set(CMAKE_CXX_COMPILER_ARG1 "-std=c++11 -DRAPIDJSON_HAS_STDSTRING=1" CACHE STRING "Compiler Args" FORCE)
FrameBuffer
  • 757
  • 1
  • 7
  • 26
  • 1
    Should it be `CMAKE_CXX_FLAGS` variable instead? – Tsyvarev Sep 15 '15 at 22:37
  • I don't know, I can't try it right now. But my project now compiles fine, I only just want the eclipse project to recognize that definition so the Indexer works ok. When I get back to home, I will try setting CMAKE_CXX_FLAGS. – FrameBuffer Sep 16 '15 at 08:37

1 Answers1

1

Since RapidJSON is a header-only library, You can define the macros you need, just before including rapidjson headers.

If you do not have this kind of global configuration header in your project, you can create a local header like myrapidjson.h:

#pragma once
#define RAPIDJSON_HAS_STDSTRING 1
#include "rapidjson/rapidjson.h"
// other headers if you always need them

And then when your header/implementation file needs rapidjson, just include this header first.

Milo Yip
  • 4,902
  • 2
  • 25
  • 27