File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,6 +79,17 @@ else(WIN32)
7979 install (FILES "${CMAKE_CURRENT_BINARY_DIR} /dg_ctl"
8080 DESTINATION ${INSTALL_BIN_DIR} )
8181endif (WIN32 )
82+ find_package (Clang REQUIRED )
83+ include_directories (${LLVM_INCLUDE_DIRS} )
84+ separate_arguments (LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS} )
85+ add_definitions (${LLVM_DEFINITIONS_LIST} )
86+ # Find the libraries that correspond to the LLVM components
87+ # that we wish to use
88+ llvm_map_components_to_libnames (llvm_libs support core irreader )
89+
90+ # Link against LLVM libraries
91+ target_link_libraries (drogon_ctl PRIVATE ${llvm_libs} )
92+
8293set (ctl_targets _drogon_ctl drogon_ctl)
8394set_property (TARGET ${ctl_targets} PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD} )
8495set_property (TARGET ${ctl_targets} PROPERTY CXX_STANDARD_REQUIRED ON )
Original file line number Diff line number Diff line change 3030#endif
3131#include < fstream>
3232
33+ #include < clang-c/Index.h>
34+
3335using namespace drogon_ctl ;
3436
3537static void forEachControllerHeaderIn (
@@ -78,11 +80,20 @@ static void forEachControllerHeaderIn(
7880static void parseControllerHeader (const std::string &headerFile,
7981 Json::Value &docs)
8082{
81- std::ifstream infile (headerFile);
82-
83- for (std::string buffer; std::getline (infile, buffer);)
83+ CXIndex index = clang_createIndex (0 , 0 );
84+ CXTranslationUnit unit = clang_parseTranslationUnit (
85+ index,
86+ headerFile.c_str (), nullptr , 0 ,
87+ nullptr , 0 ,
88+ CXTranslationUnit_None);
89+ if (unit == nullptr )
8490 {
91+ std::cerr << " Unable to parse translation unit. Quitting." << std::endl;
92+ exit (-1 );
8593 }
94+
95+ clang_disposeTranslationUnit (unit);
96+ clang_disposeIndex (index);
8697}
8798static std::string makeSwaggerDocument (const Json::Value &config)
8899{
You can’t perform that action at this time.
0 commit comments