Skip to content

Commit

Permalink
Less cmake warnings. Reflection parser takes strings for path lists only
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu343726 committed Apr 3, 2016
1 parent 9acd0dc commit 34b204d
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 95 deletions.
28 changes: 0 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,9 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

add_subdirectory(3rdParty/ctti)
include_directories(3rdParty/ctti/include)
include_directories(3rdParty/cppasscii/snippets)
include(3rdParty/cmake/exec_target.cmake)

configure_exec_targets(PROJECT CPP)
include_directories(include)

if(NOT MSVC)

# gtest needs fileno() function at file gtest/include/gtest/internal/gtest-port.h,
# but is considered an extension in cygwin GCC setup. Use GNU extensions.
# See http://stackoverflow.com/questions/18784112/googletest-1-6-with-cygwin-1-7-compile-error-fileno-was-not-declared-in-this
if(CYGWIN)
set(STD_CXX gnu++14)
else()
set(STD_CXX c++14)
endif()

set(CPP_GLOBAL_ALL_COMPILE_OPTIONS -std=${STD_CXX} -Wall -pedantic -DCTTI_STRING_MAX_LENGTH=1024 -ftemplate-depth-1024)
set(CPP_GLOBAL_DEBUG_COMPILE_OPTIONS -O0 -g3)
set(CPP_GLOABL_RELEASE_COMPILE_OPTIONS -O3 -g0 -fno-inline -fno-elide-constructors)
else()
set(CPP_GLOBAL_ALL_COMPILE_OPTIONS /DCTTI_STRING_MAX_LENGTH=512)
endif()

include(cmake/deftargets.cmake)

add_subdirectory(src)
add_subdirectory(examples)

enable_testing()
add_subdirectory(tests)

12 changes: 7 additions & 5 deletions cmake/deftargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ include(cmake/gmock)

add_library(ctti INTERFACE)
target_include_directories(ctti INTERFACE ${CMAKE_SOURCE_DIR}/3rdParty/ctti/include)
target_compile_definitions(ctti INTERFACE
$<$<CXX_COMPILER_ID:MSVC>: -DCTTI_STRING_MAX_LENGTH=512>
$<$<OR:$<CXX_COMPILER_ID:gcc>,$<CXX_COMPILER_ID:clang>>: -DCTTI_STRING_MAX_LENGTH=1024>
)

if(MSVC)
target_compile_definitions(ctti INTERFACE -DCTTI_STRING_MAX_LENGTH=512)
else()
target_compile_definitions(ctti INTERFACE -DCTTI_STRING_MAX_LENGTH=1024)
endif()

set(NAMESPACE_SEPARATOR "-")

Expand Down Expand Up @@ -176,7 +178,7 @@ function(add_siplasplas_target NAME TARGET_TYPE)
set(STD_CXX c++14)
endif()

set(common_options -std=${STD_CXX} -Wall -pedantic -DCTTI_STRING_MAX_LENGTH=1024 -ftemplate-depth-1024)
set(common_options -std=${STD_CXX} -Wall -pedantic -ftemplate-depth-1024)
set(debug_options -O0 -g3)
set(release_options -O3 -g0)
endif()
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ if(NOT MINGW) # See https://github.com/GueimUCM/siplasplas/issues/16
endif()

# Meta examples
add_example(meta DEPENDS INTERFACE siplasplas-utility)
add_example(meta DEPENDS siplasplas-utility)
40 changes: 20 additions & 20 deletions include/siplasplas/allocator/stl_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace cpp
using reference = T&;
using const_reference = const T&;

using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_move_assignment = std::true_type;

STLAllocator() = default;
STLAllocator(const STLAllocator&) = default;
STLAllocator(STLAllocator&&) = default;
STLAllocator(const STLAllocator&) = default;
STLAllocator(STLAllocator&&) = default;

STLAllocator(char* begin, char* end, std::size_t fence = 0, unsigned char cannary = 0xff) :
Allocator{begin, end}
Expand All @@ -35,17 +35,17 @@ namespace cpp
Allocator{allocator}
{}

// Rebind-aware ctors
// Rebind-aware ctors

template<typename U>
STLAllocator(const STLAllocator<U, Allocator>& alloc) :
Allocator{ static_cast<const Allocator&>(alloc) }
{}
template<typename U>
STLAllocator(const STLAllocator<U, Allocator>& alloc) :
Allocator{ static_cast<const Allocator&>(alloc) }
{}

template<typename U>
STLAllocator(STLAllocator<U, Allocator>&& alloc) :
Allocator{ std::move( static_cast<const Allocator&>(alloc) ) }
{}
template<typename U>
STLAllocator(STLAllocator<U, Allocator>&& alloc) :
Allocator{ std::move( static_cast<const Allocator&>(alloc) ) }
{}

const Allocator& raw_allocator() const
{
Expand All @@ -59,7 +59,7 @@ namespace cpp

pointer allocate(std::size_t count)
{
const std::size_t blockSize = sizeof(value_type)*count;
const std::size_t blockSize = sizeof(value_type)*count;
char* user_ptr = reinterpret_cast<char*>(Allocator::allocate(blockSize, alignof(value_type)));

if(user_ptr)
Expand Down Expand Up @@ -104,15 +104,15 @@ namespace cpp
return !(lhs == rhs);
}

std::string dump() const
{
std::ostringstream os;
std::string dump() const
{
std::ostringstream os;

os << "STLAllocator adapter for " << ctti::type_id<Allocator>().name() << ": \n"
" - Type: " << ctti::type_id<T>().name() << " (" << sizeof(T) << " bytes, alignment: " << alignof(T) << ")\n"
<< Allocator::dump();
os << "STLAllocator adapter for " << ctti::type_id<Allocator>().name() << ": \n"
" - Type: " << ctti::type_id<T>().name() << " (" << sizeof(T) << " bytes, alignment: " << alignof(T) << ")\n"
<< Allocator::dump();

return os.str();
return os.str();
}
};

Expand Down
51 changes: 32 additions & 19 deletions include/siplasplas/reflection/parser/DRLParser
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,32 @@ class App:
print ' {}{}{}'.format(Fore.MAGENTA, '='*len(message), Fore.RESET)
print ''

def split_argument(self, arg):
if arg:
return [x.strip() for x in arg[1:-1].split(self.args.list_separator)]
else:
return []

def __init__(self):
self.splashscreen('Dynamic Reflection Library Parser')
self.logger = Logger(Fore.MAGENTA)

parser = argparse.ArgumentParser(description='Dynamic Reflection Library Parser')
parser.add_argument('--compile-options', default = '', help = 'Clang compile options')
parser.add_argument('-f', '--files', nargs = '*', default = [], help = 'List of input files to process')
parser.add_argument('-d', '--database', default = '', help = 'Compilation database JSON file')
parser.add_argument('-S', '--searchdirs', default = [], help = 'List of include directories to scan for more input files')
parser.add_argument('-I', '--includedirs', default = [], help = 'Extra include directories for libclang parser')
parser.add_argument('-s', '--sourcedir', help = 'Project source directory')
parser.add_argument('-x', '--exclude', nargs = '*', default = [], help = 'List of GLOBs to exclude source files from include directories scan')
parser.add_argument('-e', '--extensions', nargs = '*', default = ['.hpp', '.h', '.hxx'], help = 'List of file extensions used for include directory input files scan')
parser.add_argument('--compile-options', default = '', help = 'Clang compile options')
parser.add_argument('-f', '--files', default = '', help = 'List of input files to process')
parser.add_argument('-d', '--database', default = '', help = 'Compilation database JSON file')
parser.add_argument('-S', '--searchdirs', default = '', help = 'List of include directories to scan for more input files')
parser.add_argument('-I', '--includedirs', default = '', help = 'Extra include directories for libclang parser')
parser.add_argument('-s', '--sourcedir', help = 'Project source directory')
parser.add_argument('-x', '--exclude', nargs = '*', default = [], help = 'List of GLOBs to exclude source files from include directories scan')
parser.add_argument('-e', '--extensions', nargs = '*', default = ['.hpp', '.h', '.hxx'], help = 'List of file extensions used for include directory input files scan')
parser.add_argument('-i', '--ignore-database', action = 'store_true', help = 'Ignore database records (Ignore input file timestamps, process file always)')
parser.add_argument('-l', '--libclang', help = 'Full path to libclang library (libclang.so)')
parser.add_argument('-a', '--ast-dump', help = 'Dumps the AST of each translation unit to a source_file.ast file', action = 'store_true')
parser.add_argument('--code-template-file', help = 'Template file for reflection code generation')
parser.add_argument('-l', '--libclang', help = 'Full path to libclang library (libclang.so)')
parser.add_argument('-a', '--ast-dump', help = 'Dumps the AST of each translation unit to a source_file.ast file', action = 'store_true')
parser.add_argument('--code-template-file', help = 'Template file for reflection code generation')
parser.add_argument('-v', '--verbose', action = 'store_true')
parser.add_argument('-o', '--output-dir', help = 'Output root directory')
parser.add_argument('-o', '--output-dir', help = 'Output root directory')
parser.add_argument('--list-separator', default = ',', help = 'Separator character used to split arguments into lists')
self.args = parser.parse_args()

GlobalLogger.enabled(self.args.verbose)
Expand All @@ -142,22 +149,23 @@ class App:
self.logger.step('libclang.so: ' + os.path.abspath(config.get_filename()))


self.args.compile_options = self.args.compile_options[1:-1]
self.args.compile_options += ' -DSIPLASPLAS_REFLECTION_RUNNING_DRLPARSER'

self.args.compile_options = self.split_argument(self.args.compile_options)
self.args.compile_options.append('-DSIPLASPLAS_REFLECTION_RUNNING_DRLPARSER')
self.args.files = self.split_argument(self.args.files)
self.args.searchdirs = self.split_argument(self.args.searchdirs)
self.args.includedirs = self.split_argument(self.args.includedirs)

self.logger.step('Database file: {}'.format(self.args.database))
self.logger.step('Extensions: ' + ', '.join(self.args.extensions))
self.logger.step('Exclude: ' + ', '.join(self.args.exclude))
self.logger.step('Compile options: ' + self.args.compile_options)
self.logger.step('Compile options: ' + ' '.join(self.args.compile_options))
self.logger.step('Template file: ' + self.args.code_template_file)
self.logger.step('Output directory: ' + self.args.output_dir)

self.logger = Logger(Fore.YELLOW)

if self.args.searchdirs:
self.args.searchdirs = self.args.searchdirs.split()
self.logger.start('Scanning include directories:')
self.logger.start('Scanning search directories:')

for search_dir in self.args.searchdirs:
directory_files = self.search_files(search_dir)
Expand All @@ -171,11 +179,16 @@ class App:

self.args.files.sort()

self.logger.start('Extra include directories:')

for dir in self.args.includedirs:
self.logger.step(dir)

includes = ['-I{}'.format(os.path.abspath(i)) for i in (self.args.searchdirs + self.args.includedirs)]
includes.append('-I' + os.path.abspath(self.args.sourcedir))
includes.append('-I' + os.path.abspath(os.path.join(self.args.sourcedir, 'include')))

compileArgs = includes + self.args.compile_options.split()
compileArgs = includes + self.args.compile_options

if not self.args.database:
self.args.database = os.path.join(self.args.output_dir, 'dlrparser_database.json')
Expand Down
48 changes: 37 additions & 11 deletions include/siplasplas/reflection/parser/drlparser.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ function(libclang_include_dir _ret)
set(${_ret} "${CLANG_PATH}/../lib/clang/${CLANG_VERSION}" PARENT_SCOPE)
endfunction()

function(get_target_include_directories TARGET RESULT)
get_target_property(type ${TARGET} TYPE)

message(STATUS "Getting includes of target '${TARGET}'")

if(type STREQUAL "INTERFACE_LIBRARY")
get_target_property(deps ${TARGET} INTERFACE_LINK_LIBRARIES)
get_target_property(includes ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)
else()
get_target_property(deps ${TARGET} LINK_LIBRARIES)
get_target_property(includes ${TARGET} INCLUDE_DIRECTORIES)
endif()

if(deps)
foreach(dep ${deps})
get_target_include_directories(${dep} dep_includes)
list(APPEND includes ${dep_includes})
endforeach()
endif()

if(includes)
list(REMOVE_DUPLICATES includes)
endif()
set(${RESULT} ${includes} PARENT_SCOPE)
endfunction()

function(reflection_target TARGET)
function(log MESSAGE)
if(SIPLASPLAS_VERBOSE_CONFIG)
Expand All @@ -160,9 +186,8 @@ function(reflection_target TARGET)
endif()

get_target_property(SOURCES ${TARGET} SOURCES)
get_target_property(INCLUDE_DIRS ${TARGET} INCLUDE_DIRECTORIES)
get_target_property(INTERFACE_INCLUDE_DIRS ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(COMPILE_OPTIONS ${TARGET} COMPILE_OPTIONS)
get_target_include_directories(${TARGET} INCLUDE_DIRS)

if(UNIX OR MINGW)
clangxx_stdlibcpp_includes(STDLIBCPP_INCLUDES)
Expand All @@ -185,7 +210,7 @@ function(reflection_target TARGET)
)

list(APPEND INCLUDE_DIRS ${INTERFACE_INCLUDE_DIRS})

log("Processing target ${TARGET}:")

foreach(source ${SOURCES})
Expand All @@ -204,12 +229,12 @@ function(reflection_target TARGET)
log("Setting preprocessor hook for target ${TARGET}")
add_custom_target(${TARGET}_prebuild)
add_dependencies(${TARGET} ${TARGET}_prebuild)
string(REGEX REPLACE ";" " " SOURCES "${SOURCES}")
string(REGEX REPLACE ";" " " INCLUDE_DIRS "${INCLUDE_DIRS}")
string(REGEX REPLACE ";" "," SOURCES "${SOURCES}")
string(REGEX REPLACE ";" "," INCLUDE_DIRS "${INCLUDE_DIRS}")

if(EXTRA_LIBCLANG_INCLUDES)
string(REGEX REPLACE ";" " " EXTRA_LIBCLANG_INCLUDES "${EXTRA_LIBCLANG_INCLUDES}")
set(includedirs --includedirs ${EXTRA_LIBCLANG_INCLUDES})
string(REGEX REPLACE ";" "," EXTRA_LIBCLANG_INCLUDES "${EXTRA_LIBCLANG_INCLUDES}")
set(includedirs --includedirs "\"${EXTRA_LIBCLANG_INCLUDES}\"")
endif()

if(DRLPARSER_DATABASE)
Expand Down Expand Up @@ -237,11 +262,11 @@ function(reflection_target TARGET)
set(astdump --ast-dump)
endif()

string(REGEX REPLACE ";" " " COMPILE_OPTIONS "${COMPILE_OPTIONS}")
string(REGEX REPLACE ";" "," COMPILE_OPTIONS "${COMPILE_OPTIONS}")

set(options
--compile-options \"${COMPILE_OPTIONS}\"
--searchdirs ${INCLUDE_DIRS}
--compile-options "\"${COMPILE_OPTIONS}\""
--searchdirs "\"${INCLUDE_DIRS}\""
${includedirs}
-s ${CMAKE_SOURCE_DIR}
-o ${OUTPUT_DIR}
Expand All @@ -256,7 +281,8 @@ function(reflection_target TARGET)

add_custom_command(
TARGET ${TARGET}_prebuild POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/${DRLPARSER_SCRIPT} ${options}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/${DRLPARSER_SCRIPT}
${options}
VERBATIM
)
endfunction()
3 changes: 2 additions & 1 deletion src/allocator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ SOURCES
linear_allocator.cpp
embedded_allocator.cpp
DEPENDS
PUBLIC siplasplas-utility
siplasplas-utility
ctti
)
8 changes: 4 additions & 4 deletions src/metatype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

add_siplasplas_library(siplasplas-metatype
SOURCES
metatype.cpp
metatype.cpp
DEPENDS
ctti
siplasplas-utility
)
ctti
siplasplas-utility
)
1 change: 1 addition & 0 deletions src/reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ SOURCES
DEPENDS
siplasplas-allocator
siplasplas-utility
ctti
)
8 changes: 5 additions & 3 deletions src/utility/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

add_siplasplas_library(siplasplas-utility
SOURCES
memory_manip.cpp
printers.cpp
)
memory_manip.cpp
printers.cpp
DEPENDS
ctti
)
4 changes: 2 additions & 2 deletions src/variant/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_siplasplas_header_only_library(siplasplas-variant
DEPENDS
ctti
)
ctti
)
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ function(add_test NAME)
)
endfunction()

add_test(variant)
add_test(variant DEPENDS siplasplas-variant)
add_test(linear_allocator DEPENDS siplasplas-allocator)

0 comments on commit 34b204d

Please sign in to comment.