diff --git a/atdna/CMakeLists.txt b/atdna/CMakeLists.txt index 4698b7f..5c37001 100644 --- a/atdna/CMakeLists.txt +++ b/atdna/CMakeLists.txt @@ -44,12 +44,14 @@ set(CLANG_INCLUDE_DIR ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_BASE}/include CACHE PATH "Clang include dir" FORCE) if(UNIX) -list(APPEND PLAT_LIBS z pthread curses) -if (APPLE) + list(APPEND PLAT_LIBS z pthread curses) + if (APPLE) list(APPEND PLAT_LIBS dl) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") list(APPEND PLAT_LIBS dl) -endif() + endif() +elseif(WIN32) + list(APPEND PLAT_LIBS Mincore) endif() # Offer the user the choice of overriding the installation directories @@ -83,7 +85,7 @@ include_directories(${LLVM_INCLUDE_DIRS}) link_directories(${LLVM_LIBRARY_DIRS}) add_executable(atdna main.cpp test.hpp ${PLAT_SRCS}) target_link_libraries(atdna ${LLVM_LIBS} ${PLAT_LIBS}) -set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS +set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS "INSTALL_PREFIX=${ABS_INSTALL_BIN_DIR};__STDC_LIMIT_MACROS=1;__STDC_CONSTANT_MACROS=1") if(MSVC) set_target_properties(atdna PROPERTIES @@ -133,7 +135,7 @@ install(EXPORT atdnaTargets DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT atdna) ######### enable_testing() -add_test(NAME test-dna COMMAND $ -o test.cpp +add_test(NAME test-dna COMMAND $ -o test.cpp "-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}" ${CMAKE_SOURCE_DIR}/test.hpp) @@ -185,7 +187,7 @@ macro(atdna out) endif() # Make target - add_custom_command(OUTPUT ${out} COMMAND $ + add_custom_command(OUTPUT ${out} COMMAND $ ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}" ${ins} DEPENDS ${ins} COMMENT "Generating DNA ${out}") diff --git a/atdna/FindLLVM.cmake b/atdna/FindLLVM.cmake index 729734d..e76c075 100644 --- a/atdna/FindLLVM.cmake +++ b/atdna/FindLLVM.cmake @@ -33,7 +33,8 @@ if(WIN32) get_filename_component(LLVM_ROOT_DIR [HKEY_LOCAL_MACHINE\\Software\\LLVM\\LLVM] ABSOLUTE) endif() -set(llvm_config_names llvm-config-3.8 llvm-config38 +set(llvm_config_names llvm-config-3.9 llvm-config39 + llvm-config-3.8 llvm-config38 llvm-config-3.7 llvm-config37 llvm-config-3.6 llvm-config36 llvm-config-3.5 llvm-config35 @@ -54,7 +55,9 @@ if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG) message(FATAL_ERROR "LLVM_ROOT_DIR (${LLVM_ROOT_DIR}) is not a valid LLVM install") endif() # We incorporate the CMake features provided by LLVM: - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_ROOT_DIR}/share/llvm/cmake") + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} + "${LLVM_ROOT_DIR}/share/llvm/cmake" + "${LLVM_ROOT_DIR}/lib/cmake/llvm") include(LLVMConfig) # Set properties set(LLVM_HOST_TARGET ${TARGET_TRIPLE}) diff --git a/atdna/main.cpp b/atdna/main.cpp index a09a606..c94e93e 100644 --- a/atdna/main.cpp +++ b/atdna/main.cpp @@ -2323,22 +2323,22 @@ public: class ATDNAConsumer : public clang::ASTConsumer { + std::unique_ptr fileOut; ATDNAEmitVisitor emitVisitor; - StreamOut& fileOut; public: - explicit ATDNAConsumer(clang::ASTContext& context, StreamOut& fo) - : emitVisitor(context, fo), - fileOut(fo) {} + explicit ATDNAConsumer(clang::ASTContext& context, std::unique_ptr&& fo) + : fileOut(std::move(fo)), + emitVisitor(context, *fileOut) {} void HandleTranslationUnit(clang::ASTContext& context) { /* Write file head */ - fileOut << "/* Auto generated atdna implementation */\n" - "#include \n" - "#include \n" - "#include \n\n"; + *fileOut << "/* Auto generated atdna implementation */\n" + "#include \n" + "#include \n" + "#include \n\n"; for (const std::string& inputf : InputFilenames) - fileOut << "#include \"" << inputf << "\"\n"; - fileOut << "\n"; + *fileOut << "#include \"" << inputf << "\"\n"; + *fileOut << "\n"; /* Emit file */ emitVisitor.TraverseDecl(context.getTranslationUnitDecl()); @@ -2352,13 +2352,20 @@ public: std::unique_ptr CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef /*filename*/) { - StreamOut* fileout; + std::unique_ptr fileout; +#if LLVM_VERSION_MAJOR > 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9) if (OutputFilename.size()) fileout = compiler.createOutputFile(OutputFilename, false, true, "", "", true); else fileout = compiler.createDefaultOutputFile(false, "a", "cpp"); +#else + if (OutputFilename.size()) + fileout.reset(compiler.createOutputFile(OutputFilename, false, true, "", "", true)); + else + fileout.reset(compiler.createDefaultOutputFile(false, "a", "cpp")); +#endif AthenaError = compiler.getASTContext().getDiagnostics().getCustomDiagID(clang::DiagnosticsEngine::Error, "Athena error: %0"); - return std::unique_ptr(new ATDNAConsumer(compiler.getASTContext(), *fileout)); + return std::unique_ptr(new ATDNAConsumer(compiler.getASTContext(), std::move(fileout))); } }; @@ -2372,9 +2379,6 @@ int main(int argc, const char** argv) "-fsyntax-only", "-std=c++14", "-D__atdna__=1", -#if _WIN32 - "-D__is_assignable(a,b)=false", /* HACK HACKITY HACK HACK: Microsoft, play nice with the other kids*/ -#endif "-I" XSTR(INSTALL_PREFIX) "/lib/clang/" CLANG_VERSION_STRING "/include", "-I" XSTR(INSTALL_PREFIX) "/include/Athena"}; for (int a=1 ; a