Skip to content

Commit

Permalink
Add tool flag to set clang executable for cppast
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu343726 committed Feb 23, 2019
1 parent c7e633e commit 1166caf
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ user-integration-gcc8-x86-llvm6.0.0:
tags:
- linux
- docker
retry: 2
script:
- conan create tool Manu343726/testing --build=missing --build=tinyrefl-tool
- conan create . Manu343726/testing --build=missing --build=tinyrefl
Expand Down
13 changes: 13 additions & 0 deletions cmake/tinyrefl_tool-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ set(TINYREFL_PACKAGE_BIN_DIR "${TINYREFL_PACKAGE_DIR}/bin")
set(TINYREFL_TOOL_EXECUTABLE_FILENAME tinyrefl-tool)
set(__TINYREFL_TOOL_EXECUTABLE_EXPECTED_PATH "${TINYREFL_PACKAGE_DIR}/bin/${TINYREFL_TOOL_EXECUTABLE_FILENAME}")

if(CONAN_BIN_DIRS_CLANG_EXECUTABLES)
message(STATUS "tinyrefl_tool config using clang binaries from conan")
find_program(clangpp_executable clang++ PATHS "${CONAN_BIN_DIRS_CLANG_EXECUTABLES}" NO_DEFAULT_PATH)
else()
message(STATUS "tinyrefl_tool config will search system clang binaries")
find_program(clangpp_executable clang++)
endif()

if(clangpp_executable)
set(TINYREFL_TOOL_CLANGPP_EXECUTABLE "${clangpp_executable}")
message(STATUS "tinyrefl_tool config found clang++: ${TINYREFL_TOOL_CLANGPP_EXECUTABLE}")
endif()

if(EXISTS "${__TINYREFL_TOOL_EXECUTABLE_EXPECTED_PATH}")
set(TINYREFL_TOOL_EXECUTABLE "${__TINYREFL_TOOL_EXECUTABLE_EXPECTED_PATH}")
set(TINYREFL_SOURCE_DIR "${TINYREFL_PACKAGE_DIR}")
Expand Down
2 changes: 1 addition & 1 deletion tool/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TinyreflTool(ConanFile):
'ctti/0.0.2@Manu343726/testing',
'cppast/master@Manu343726/testing',
'llvm_support/6.0.1@Manu343726/testing')
requires = (('clang_executables/6.0.1@Manu343726/testing', 'private'),)
requires = 'clang_executables/6.0.1@Manu343726/testing'
default_options = 'fmt:header_only=True'
settings = 'os', 'compiler', 'build_type', 'arch'

Expand Down
7 changes: 6 additions & 1 deletion tool/driver.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ function(tinyrefl_tool)
list(APPEND definitions "-D${definition}")
endforeach()

if(TINYREFL_TOOL_CLANGPP_EXECUTABLE)
message(STATUS "tinyrefl-tool using clang++ binary: ${TINYREFL_TOOL_CLANGPP_EXECUTABLE}")
set(clang_executable_option "--clang-binary=\"${TINYREFL_TOOL_CLANGPP_EXECUTABLE}\"")
endif()

string(REGEX REPLACE ";" " " header_list "${ARGS_HEADERS}")
string(REGEX REPLACE ";" " " includes_list "${includes}")
string(REGEX REPLACE ";" " " options_list "${compile_options}")
Expand All @@ -95,7 +100,7 @@ function(tinyrefl_tool)

add_prebuild_command(TARGET ${ARGS_TARGET}
NAME "${command_target_name}"
COMMAND ${TINYREFL_TOOL_EXECUTABLE} ${header} -std=c++${CMAKE_CXX_STANDARD} ${definitions} ${includes} ${compile_options}
COMMAND ${TINYREFL_TOOL_EXECUTABLE} ${header} ${clang_executable_option} -std=c++${CMAKE_CXX_STANDARD} ${definitions} ${includes} ${compile_options}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating tinyrefl metadata for ${ARGS_TARGET}/${header}"
DEPENDS ${TINYREFL_TOOL_TARGET}
Expand Down
2 changes: 1 addition & 1 deletion tool/external/external.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if(NOT TINYREFL_CPPAST_REPO_URL)
set(TINYREFL_CPPAST_REPO_URL https://github.com/Manu343726/cppast.git)
endif()
if(NOT TINYREFL_CPPAST_VERSION)
set(TINYREFL_CPPAST_VERSION bytech)
set(TINYREFL_CPPAST_VERSION master)
endif()
if(NOT TINYREFL_CPPFS_REPO_URL)
set(TINYREFL_CPPFS_REPO_URL https://github.com/Manu343726/cppfs.git)
Expand Down
15 changes: 15 additions & 0 deletions tool/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PROJECT(TinyreflToolExample)
cmake_minimum_required(VERSION 3.0)

set(CMAKE_CXX_STANDARD 14)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

CONAN_BASIC_SETUP(TARGETS)

message(STATUS "CONAN_BIN_DIRS_CLANG_EXECUTABLES: ${CONAN_BIN_DIRS_CLANG_EXECUTABLES}")

add_library(tinyrefl_tool_example dummy.cpp)

find_package(tinyrefl_tool REQUIRED)
tinyrefl_tool(TARGET tinyrefl_tool_example HEADERS example.hpp)
19 changes: 19 additions & 0 deletions tool/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans.model.conan_file import ConanFile
from conans import CMake
import os

class DefaultNameConan(ConanFile):
name = "DefaultName"
version = "0.1"
settings = "os", "compiler", "arch", "build_type"
generators = "cmake"
build_requires = 'tinyrefl-tool/0.3.1@Manu343726/testing'

def build(self):
cmake = CMake(self, parallel=False)
cmake.verbose = True
cmake.configure()
cmake.build()

def test(self):
pass
Empty file added tool/test_package/dummy.cpp
Empty file.
31 changes: 31 additions & 0 deletions tool/test_package/example.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef TINYREFL_TESTPACKAGE_EXAMPLE_HPP
#define TINYREFL_TESTPACKAGE_EXAMPLE_HPP

namespace example
{

class Example
{
public:
Example() = default;

int getInt() const
{
return 42;
}

int i = 42;

enum class Enum
{
A,
B,
C
};

Enum e = Enum::A;
};

}; // namespace example

#endif // TINYREFL_TESTPACKAGE_EXAMPLE_HPP
22 changes: 20 additions & 2 deletions tool/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,8 @@ bool reflect_file(
cl::list<std::string>& include_dirs,
cl::list<std::string>& definitions,
cl::list<std::string>& warnings,
const std::vector<std::string>& custom_flags)
const std::vector<std::string>& custom_flags,
const std::string& clang_binary)
{
using parser_t = cppast::simple_file_parser<cppast::libclang_parser>;

Expand All @@ -841,6 +842,17 @@ bool reflect_file(
parser_t::config config;
config.set_flags(cpp_standard);

if(!clang_binary.empty())
{
if(!config.set_clang_binary(clang_binary))
{
std::cerr
<< "error configuring cppast libclang parser: Clang binary \""
<< clang_binary << "\" not found\n";
std::exit(1);
}
}

std::cout << "parsing file " << filepath << " "
<< cppast::to_string(cpp_standard) << " ";

Expand Down Expand Up @@ -961,6 +973,11 @@ int main(int argc, char** argv)
cppast::cpp_standard::cpp_1z, "c++17", "C++ 2017 standard"))};
cl::list<std::string> custom_flags{cl::Sink,
cl::desc("Custom compiler flags")};
cl::opt<std::string> clang_binary{
"clang-binary",
cl::ValueOptional,
cl::desc(
"clang++ binary. If not given, tinyrefl-tool will search in your PATH")};

#if TINYREFL_LLVM_VERSION_MAJOR >= 6
cl::SetVersionPrinter([](llvm::raw_ostream& out) { print_version(out); });
Expand All @@ -976,7 +993,8 @@ int main(int argc, char** argv)
includes,
definitions,
warnings,
custom_flags))
custom_flags,
clang_binary))
{
return 0;
}
Expand Down

0 comments on commit 1166caf

Please sign in to comment.