Skip to content

Commit

Permalink
Package-friendly configuration. Bootstrap script
Browse files Browse the repository at this point in the history
  • Loading branch information
manusharded committed Sep 1, 2016
1 parent fdaf2c9 commit ea977c8
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 73 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set(SIPLASPLAS_VERSION_MINOR 0)
set(SIPLASPLAS_VERSION_PATCH 0)

set(SIPLASPLAS_DRLPARSER_PYTHON_VERSION 2.7)
set(SIPLASPLAS_BUILDING_FROM_SOURCES TRUE CACHE INTERNAL "")
set(SIPLASPLAS_ROOT "${CMAKE_SOURCE_DIR}")

include(cmake/deftargets.cmake)
include(cmake/install.cmake)
Expand All @@ -31,6 +33,9 @@ option(SIPLASPLAS_ENABLE_VALGRIND "Enable memory check of executable targets" OF
option(SIPLASPLAS_ENABLE_ASSERTS "Force assertions, which are disabled by default on Release build" OFF)
option(SIPLASPLAS_DUMP_ERRORS "Dump error logs after running an executable. Implies SIPLASPLAS_CLEAR_LOGS" ON)

include(cmake/siplasplas.cmake)

add_subdirectory(cmake)
add_subdirectory(3rdParty)
add_subdirectory(src)

Expand Down
27 changes: 27 additions & 0 deletions bootstrap.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
if(NOT SIPLASPLAS_ROOT)
if(SIPLASPLAS_PACKAGE_URL)
set(SIPLASPLAS_PACKAGE "${CMAKE_BINARY_DIR}/siplasplas_package")
file(DOWNLOAD "${SIPLASPLAS_PACKAGE_URL}" "${SIPLASPLAS_PACKAGE}" SHOW_PROGRESS)
endif()

if(NOT SIPLASPLAS_PACKAGE OR NOT EXISTS "${SIPLASPLAS_PACKAGE}")
message(FATAL_ERROR "No siplasplas package found")
endif()

get_filename_component(SIPLASPLAS_PACKAGE_NAME "${SIPLASPLAS_PACKAGE}" NAME_WE)

if(NOT EXISTS "${SIPLASPLAS_PACKAGE_NAME}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xvf "${SIPLASPLAS_PACKAGE}"
)
endif()

set(SIPLASPLAS_ROOT "${CMAKE_BINARY_DIR}/${SIPLASPLAS_PACKAGE_NAME}" CACHE INTERNAL "")
endif()

if(EXISTS "${SIPLASPLAS_ROOT}")
list(APPEND CMAKE_MODULE_PATH "${SIPLASPLAS_ROOT}/cmake")
include(siplasplas)
else()
message(FATAL_ERROR "The siplasplas root directory (${SIPLASPLAS_ROOT}) does not exist")
endif()
11 changes: 11 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
install(
FILES
utils.cmake
libclang.cmake
pip.cmake
FindLibClang.cmake
FindPythonPip.cmake
siplasplas.cmake
DESTINATION
cmake/
)
2 changes: 1 addition & 1 deletion cmake/cpacksettings.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

set(PACKAGE_VARIANT "${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}-${CMAKE_BUILD_TYPE}")

if(SIPLASPLAS_LIBRARIES_STATIC)
Expand All @@ -23,6 +22,7 @@ string(REGEX REPLACE "\n" "" branch "${branch}")
string(REGEX REPLACE " " "-" branch "${branch}")

set(CPACK_PACKAGE_FILE_NAME "siplasplas-${branch}-${PACKAGE_VARIANT}")
string(REGEX REPLACE "\\." "_" CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}")
set(CPACK_PACKAGE_VENDOR "Manu Sánchez")
set(CPACK_PACKAGE_DESCRIPTION "Examples and utilities for the Advanced C++ course for the GUEIM association, Complutense University of Madrid")
set(CPACK_PACKAGE_VERSION_MAJOR ${SIPLASPLAS_VERSION_MAJOR})
Expand Down
11 changes: 2 additions & 9 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@ function(install_siplasplas_library TARGET)
RUNTIME DESTINATION bin
COMPONENT libraries
)

headerdir_from_sourcetree(dir)
install(DIRECTORY ${dir} DESTINATION include/siplasplas
COMPONENT headers
)
endfunction()

function(install_siplasplas_headeronly_library TARGET)
headerdir_from_sourcetree(dir)
install(DIRECTORY ${dir} DESTINATION include/siplasplas
COMPONENT headers
)
endfunction()

function(install_siplasplas_example EXAMPLE)
Expand All @@ -40,3 +31,5 @@ function(install_siplasplas_example EXAMPLE)
)
endif()
endfunction()

install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/siplasplas" DESTINATION include/)
19 changes: 13 additions & 6 deletions cmake/libclang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ if(SIPLASPLAS_DOWNLOAD_LIBCLANG)
if(length EQUAL 1)
if(IS_DIRECTORY "${CMAKE_BINARY_DIR}/llvm/${llvm_contents}")
set(llvm_root "${CMAKE_BINARY_DIR}/llvm/${llvm_contents}")
string(STRIP llvm_root "${llvm_root}")
else()
message(FATAL_ERROR "Extracted llvm directory \"${llvm_contents}\" is not a directory")
endif()
Expand All @@ -129,10 +130,14 @@ if(SIPLASPLAS_DOWNLOAD_LIBCLANG)
message(FATAL_ERROR "LLVM package contents not recognized, only a root directory was expected")
endif()

find_library(libclang_library NAMES clang libclang HINTS "${llvm_root}/lib")
if(WIN32)
set(libclang_library "${llvm_root}/lib/libclang.dll")
else()
set(libclang_library "${llvm_root}/lib/libclang.so")
endif()

# Write output variables:
if(libclang_library)
if(libclang_library AND EXISTS "${libclang_library}")
set(SIPLASPLAS_LIBCLANG_LIBRARY "${libclang_library}")
else()
message(FATAL_ERROR "Could not find libclang library at ${llvm_root}/lib")
Expand Down Expand Up @@ -168,10 +173,12 @@ endif()

string(REGEX REPLACE "([0-9]+\\.[0-9]+)\\.[0-9]+" "\\1" SIPLASPLAS_LIBCLANG_VERSION_MAJOR_MINOR "${SIPLASPLAS_LIBCLANG_VERSION}")

message(STATUS "libclang version: ${SIPLASPLAS_LIBCLANG_VERSION} (${SIPLASPLAS_LIBCLANG_VERSION_MAJOR_MINOR})")
message(STATUS "libclang library: ${SIPLASPLAS_LIBCLANG_LIBRARY}")
message(STATUS "libclang include dir: ${SIPLASPLAS_LIBCLANG_INCLUDE_DIR}")
message(STATUS "libclang system include dir: ${SIPLASPLAS_LIBCLANG_SYSTEM_INCLUDE_DIR}")
if(SIPLASPLAS_VERBOSE_CONFIG)
message(STATUS "libclang version: ${SIPLASPLAS_LIBCLANG_VERSION} (${SIPLASPLAS_LIBCLANG_VERSION_MAJOR_MINOR})")
message(STATUS "libclang library: ${SIPLASPLAS_LIBCLANG_LIBRARY}")
message(STATUS "libclang include dir: ${SIPLASPLAS_LIBCLANG_INCLUDE_DIR}")
message(STATUS "libclang system include dir: ${SIPLASPLAS_LIBCLANG_SYSTEM_INCLUDE_DIR}")
endif()

function(gxx_executable _ret)
if(SIPLASPLAS_GXX)
Expand Down
22 changes: 22 additions & 0 deletions cmake/siplasplas.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if(NOT SIPLASPLAS_ROOT)
message(FATAL_ERROR "siplasplas installation not found. Use SIPLASPLAS_ROOT variable to specify the path to your siplasplas installation")
endif()

set(SIPLAPLAS_LIB_DIR "${SIPLASPLAS_ROOT}/lib" CACHE INTERNAL "")
set(SIPLASPLAS_CMAKE_DIR "${SIPLASPLAS_ROOT}/cmake" CACHE INTERNAL "")
set(SIPLASPLAS_BIN_DIR "${SIPLASPLAS_ROOT}/bin" CACHE INTERNAL "")
set(SIPLASPLAS_INCLUDE_DIR "${SIPLASPLAS_ROOT}/include" CACHE INTERNAL "")

if(NOT SIPLASPLAS_DRLPARSER_PYTHON_VERSION)
set(SIPLASPLAS_DRLPARSER_PYTHON_VERSION 2.7)
endif()

if(SIPLASPLAS_BUILDING_FROM_SOURCES)
set(SIPLASPLAS_DRLPARSER_DIR "${CMAKE_SOURCE_DIR}/src/reflection/parser")
else()
set(SIPLASPLAS_DRLPARSER_DIR "${SIPLASPLAS_BIN_DIR}/reflection-parser/parser" CACHE INTERNAL "")
endif()
list(APPEND CMAKE_MODULE_PATH "${SIPLASPLAS_CMAKE_DIR}" "${SIPLASPLAS_DRLPARSER_DIR}")

include(utils)
include(drlparser)
3 changes: 3 additions & 0 deletions cmake/thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,15 @@ function(add_siplasplas_thirdparty_component NAME)

if(COMPONENT_SHARED)
compute_binary_file(${COMPONENT_BINARY_NAME} SHARED "${COMPONENT_LIBRARY_SUFFIX}${COMPONENT_SHARED_LIBRARY_SUFFIX}" "${COMPONENT_BINARY_DIR}" libfile)
install(FILES "${binary_dir}/${libfile}" DESTINATION lib)

# We should import the location of the import lib (.lib) too to link with the dll
# (In dll platforms you link against the import lib, not the dynamic library)
if(MSVC)
compute_binary_file(${COMPONENT_BINARY_NAME} IMPORT "${COMPONENT_LIBRARY_SUFFIX}" "${COMPONENT_BINARY_DIR}" importedlibfile)
install(FILES "${binary_dir}/${importedlibfile}" DESTINATION lib)
endif()

else()
compute_binary_file(${COMPONENT_BINARY_NAME} STATIC "${COMPONENT_LIBRARY_SUFFIX}" "${COMPONENT_BINARY_DIR}" libfile)
endif()
Expand Down
1 change: 0 additions & 1 deletion cmake/utils.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Returns the relative path of the
# current source dir against the source
# tree root.
Expand Down
60 changes: 37 additions & 23 deletions src/reflection/parser/DRLParser
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Compiler:
self.outputdir = output_dir
self.print_ast = print_ast
self.jinjaTemplateFile = jinjaTemplateFile
self.verbose = verbose

import jinja2
from jinja2 import Template, Environment, FileSystemLoader
Expand All @@ -59,15 +60,17 @@ class Compiler:
self.logger.step('({}outdated{}) {}'.format(Fore.RED, Fore.RESET, self.pathformat.format(tu.filePath)))

outputfile = self._output_file(tu.filePath)
self.logger.info('Output file: {}'.format(outputfile))

if self.verbose:
self.logger.info('Output file: {}'.format(outputfile))

# Touch the output file so #include <outputfile> doesn't fail
if not os.path.exists(outputfile):
with open(outputfile, 'w') as f:
f.close()

tu.process()
tu.run_jinja(outputfile)
tu.process(self.verbose)
tu.run_jinja(outputfile, self.verbose)
self.syncmanager.sync(sourcefile, os.path.relpath(outputfile, self.sourcedir))
tu.dispose() # Release translation unit memory (Clang AST, processed AST, etc)
else:
Expand Down Expand Up @@ -114,9 +117,8 @@ class App:
return outputfiles

def splashscreen(self, message):
print '{}==>{} {}'.format(Fore.MAGENTA, Fore.RESET, message)
print ' {}{}{}'.format(Fore.MAGENTA, '='*len(message), Fore.RESET)
print ''
print message
print '{}{}{}'.format(Fore.GREEN, '='*len(message), Fore.RESET)

def split_argument(self, arg):
if arg:
Expand All @@ -135,8 +137,8 @@ class App:
return False

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

parser = argparse.ArgumentParser(description='Dynamic Reflection Library Parser')
parser.add_argument('--compile-options', default = '', help = 'Clang compile options')
Expand All @@ -146,7 +148,8 @@ class App:
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('--blacklist', nargs ='*', default = [], help = 'Subset of searchdirs to ignore')
parser.add_argument('--blacklist', default = '', help = 'Subset of searchdirs to ignore')
parser.add_argument('--no-ignore-externals', action = 'store_true', help = 'Do not ignore include directories external to the sourcetree during search')
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)')
Expand All @@ -160,27 +163,36 @@ class App:
GlobalLogger.enabled(self.args.verbose)

if self.args.libclang:
self.logger.step('libclang.so: ' + self.args.libclang)
libclang_binary = self.args.libclang
clang.cindex.Config.set_library_file(self.args.libclang)
else:
config = clang.cindex.Config()
self.logger.step('libclang.so: ' + os.path.abspath(config.get_filename()))
libclang_binary = os.path.realpath(clang.cindex.Config().get_filename())


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.args.blacklist = self.split_argument(self.args.blacklist)

# Ignore directories from outside the sourcetree by default:
if not self.args.no_ignore_externals:
self.args.blacklist += [dir for dir in self.args.searchdirs if os.path.commonprefix([dir, self.args.sourcedir]) != self.args.sourcedir]

if self.args.verbose:
self.logger.start('Settings:')

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: ' + ' '.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.step('Source directory: {}'.format(self.args.sourcedir))
self.logger.step('Libclang binary: {}'.format(libclang_binary))
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('Blacklist: ' + ', '.join(self.args.blacklist))
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.logger.start('Scanning search directories:')
Expand All @@ -195,10 +207,11 @@ class App:

self.args.files.sort()

self.logger.start('Extra include directories:')
if self.args.verbose:
self.logger.start('Extra include directories:')

for dir in self.args.includedirs:
self.logger.step(dir)
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))
Expand All @@ -213,7 +226,8 @@ class App:
self.args.sourcedir, self.args.files,
self.args.database, self.args.output_dir, self.args.ignore_database,
self.args.ast_dump,
self.args.code_template_file
self.args.code_template_file,
self.args.verbose
)

def run(self):
Expand Down
Loading

0 comments on commit ea977c8

Please sign in to comment.