From ae87bc378b2df0ed6b7f4a4013718ff478ac1569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 6 Jun 2017 14:23:03 +0200 Subject: [PATCH 1/2] Add more version macros --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dabd9d4..72a9b83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,6 +101,8 @@ add_library(cppast ${detail_header} ${header} ${source} ${libclang_source}) target_include_directories(cppast PUBLIC ../include) target_link_libraries(cppast PUBLIC type_safe _cppast_tiny_process _cppast_libclang) target_compile_definitions(cppast PUBLIC + CPPAST_VERSION_MINOR="${cppast_VERSION_MINOR}" + CPPAST_VERSION_MAJOR="${cppast_VERSION_MAJOR}" CPPAST_VERSION_STRING="${cppast_VERSION}") if(CPPAST_ENABLE_ASSERTIONS) target_compile_definitions(cppast PUBLIC CPPAST_ENABLE_ASSERTIONS) From 206c771b1d4600122cf2b23a7988b8f437571ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 6 Jun 2017 14:33:11 +0200 Subject: [PATCH 2/2] Define macros to detect cppast when parsing the code --- include/cppast/libclang_parser.hpp | 5 +++++ src/libclang/libclang_parser.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/include/cppast/libclang_parser.hpp b/include/cppast/libclang_parser.hpp index e808a54..87f590d 100644 --- a/include/cppast/libclang_parser.hpp +++ b/include/cppast/libclang_parser.hpp @@ -29,6 +29,11 @@ namespace cppast class libclang_compile_config final : public compile_config { public: + /// Creates the default configuration. + /// + /// \effects It will set the clang binary determined by the build system, + /// as well as the libclang system include directory determined by the build system. + /// It will also define `__cppast__` with the value `"libclang"` as well as `__cppast_major__` and `__cppast_minor__`. libclang_compile_config(); /// \effects Sets the path to the location of the `clang++` binary and the version of that binary. diff --git a/src/libclang/libclang_parser.cpp b/src/libclang/libclang_parser.cpp index 3bd900f..1174c09 100644 --- a/src/libclang/libclang_parser.cpp +++ b/src/libclang/libclang_parser.cpp @@ -49,13 +49,20 @@ namespace libclang_compile_config::libclang_compile_config() : compile_config({}) { + // set given clang binary auto ptr = CPPAST_CLANG_VERSION_STRING; auto major = parse_number(ptr); auto minor = parse_number(ptr); auto patch = parse_number(ptr); set_clang_binary(CPPAST_CLANG_BINARY, major, minor, patch); + // set system include dir add_include_dir(CPPAST_LIBCLANG_SYSTEM_INCLUDE_DIR); + + // set macros to detect cppast + define_macro("__cppast__", "libclang"); + define_macro("__cppast_version_major__", CPPAST_VERSION_MAJOR); + define_macro("__cppast_version_minor__", CPPAST_VERSION_MINOR); } void libclang_compile_config::do_set_flags(cpp_standard standard, compile_flags flags)