Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
djmott committed Jan 2, 2019
1 parent 7cd5112 commit 81b145c
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 164 deletions.
19 changes: 0 additions & 19 deletions CMakeLists.antlr4

This file was deleted.

94 changes: 94 additions & 0 deletions antlr.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
include_guard(GLOBAL)

find_package(Java COMPONENTS Runtime REQUIRED)

include(ExternalProject)

set(ANTLR_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/antlr)
if(MSVC)
set(ANTLR_LIB "${ANTLR_INSTALL_PREFIX}/lib/antlr4-runtime.lib")
elseif("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
set(ANTLR_LIB "${ANTLR_INSTALL_PREFIX}/lib/libantlr4-runtime.dll.a")
endif()

file(DOWNLOAD http://www.antlr.org/download/antlr-4.7.1-complete.jar ${ANTLR_INSTALL_PREFIX}/bin/antlr4.jar)

ExternalProject_Add(antlr4_runtime
PREFIX .antlr
GIT_REPOSITORY https://github.com/antlr/antlr4.git
GIT_TAG 4.7.1
GIT_SHALLOW TRUE
SOURCE_SUBDIR runtime/Cpp
UPDATE_COMMAND ""
PATCH_COMMAND ""
INSTALL_DIR ${ANTLR_INSTALL_PREFIX}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${ANTLR_INSTALL_PREFIX} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=TRUE -DBUILD_TESTS=FALSE
)

add_custom_command(OUTPUT ${ANTLR_LIB} DEPENDS antlr4_runtime COMMAND ${CMAKE_COMMAND} -E echo "building antlr library" WORKING_DIRECTORY ${ANTLR_INSTALL_PREFIX}/lib)

add_custom_target(antlr ALL DEPENDS ${ANTLR_LIB} antlr4_runtime)

#[[
Generate antlr grammar
Parameters:
INPUT <file> - required - input g4 grammar file
VISITOR - optional - generate visitor sources
LISTENER - optional - generate listener sources
NAMESPACE <name> - optional - symbols produced in specified namespace
Variables:
ANTLR_SOURCES - generated source files
ANTLR_HEADERS - generated headers
]]
function(antlr_gen)
set(_options VISITOR LISTENER)
set(_single_args INPUT NAMESPACE)
set(_multi_args)
cmake_parse_arguments(antlr "${_options}" "${_single_args}" "${_multi_args}" ${ARGN})

get_filename_component(_input ${antlr_INPUT} ABSOLUTE)
get_filename_component(_infile ${antlr_INPUT} NAME_WE)

set(ANTLR_SOURCES ${_infile}Lexer.cpp ${_infile}Parser.cpp)
set(ANTLR_HEADERS ${_infile}Lexer.h ${_infile}Parser.h)

set(_cmd ${Java_JAVA_EXECUTABLE} -Xmx500M -cp ${ANTLR_INSTALL_PREFIX}/bin/antlr4.jar org.antlr.v4.Tool -Dlanguage=Cpp)

if(antlr_VISITOR)
set(_cmd ${_cmd} -visitor)
set(ANTLR_SOURCES ${ANTLR_SOURCES} ${_infile}BaseVisitor.cpp ${_infile}Visitor.cpp)
set(ANTLR_HEADERS ${ANTLR_HEADERS} ${_infile}BaseVisitor.h ${_infile}Visitor.h)
else()
set(_cmd ${_cmd} -no-visitor)
endif()

if(antlr_LISTENER)
set(_cmd ${_cmd} -listener)
set(ANTLR_SOURCES ${ANTLR_SOURCES} ${_infile}BaseListener.cpp ${_infile}Listener.cpp)
set(ANTLR_HEADERS ${ANTLR_HEADERS} ${_infile}BaseListener.h ${_infile}Listener.h)
else()
set(_cmd ${_cmd} -no-listener)
endif()

if(antlr_NAMESPACE)
set(_cmd ${_cmd} -package ${antlr_NAMESPACE})
endif()


set(ANTLR_SOURCES ${ANTLR_SOURCES} PARENT_SCOPE)
set(ANTLR_HEADERS ${ANTLR_HEADERS} PARENT_SCOPE)

set(_cmd ${_cmd} ${_input})

add_custom_command(
OUTPUT ${_output} ${ANTLR_SOURCES} ${ANTLR_HEADERS}
DEPENDS antlr4_runtime ${_input}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
COMMAND ${CMAKE_COMMAND} -E echo ${_cmd}
COMMAND ${_cmd}
)

set(ANTLR_INCLUDE_DIR ${ANTLR_INSTALL_PREFIX}/include/antlr4-runtime PARENT_SCOPE)
endfunction()
119 changes: 0 additions & 119 deletions antlr4.cmake

This file was deleted.

66 changes: 46 additions & 20 deletions gcc.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

find_program(GCC
gcc NAMES gcc gcc.exe
NAMES gcc gcc.exe
PATHS /usr/bin /bin
DOC "Path to gcc"
)
Expand All @@ -13,46 +13,72 @@ endif()
Compile source with gcc
Parameters:
INPUT <file> - required - input source file
INPUT <file...> - required - list of inputs
OUTPUT <file> - required - generated binary
BITS <bits> - optional - specify machine type (default 64) can be one of the following:
32 32 bit build
64 64 bit build
LINK_SCRIPT <file> - optional - use linker script by passing -T <file>
FREESTANDING - optional - passes -ffreestanding
NOEXCEPTIONS - optional - passes -fno-exceptions
NORTTI - optional - passes -fno-rtti
NOSTDLIB - optional - passes -nostdlib
WALL - optonal - passes -Wall
WEXTRA - optional - passes -Wextra
FREESTANDING - optional - passes -ffreestanding
]]

function(gcc)

set(_options NOEXCEPTIONS NORTTI WALL WEXTRA FREESTANDING)
set(_single_args INPUT OUTPUT BITS)
set(_multi_args)
cmake_parse_arguments(gcc "${_options}" "${_single_args}" "${_mutli_args}" ${ARGN})
set(_single_args OUTPUT BITS LINK_SCRIPT)
set(_multi_args INPUTS)
cmake_parse_arguments(gcc "${_options}" "${_single_args}" "${_multi_args}" ${ARGN})

get_filename_component(gcc_INPUT ${gcc_INPUT} ABSOLUTE)
set(_cmd ${GCC} -o ${gcc_OUTPUT})

set(_bits_arg -m64)
if(gcc_BITS)
set(_bits_arg "-m${gcc_BITS}")
set(_cmd ${_cmd} -m${gcc_BITS})
else()
set(_cmd ${_cmd} -m64)
endif()

if(gcc_LINK_SCRIPT)
get_filename_component(gcc_LINK_SCRIPT ${gcc_LINK_SCRIPT} ABSOLUTE)
set(_cmd ${_cmd} -T ${gcc_LINK_SCRIPT})
endif()

if(gcc_NOEXCEPTIONS)
set(_cmd ${_cmd} -fno-exceptions)
endif()

if(gcc_NORTTI)
set(_cmd ${_cmd} -fno-rtti)
endif()

if(gcc_WALL)
set(_cmd ${_cmd} -Wall)
endif()

if(gcc_WEXTRA)
set(_cmd ${_cmd} -Wextra)
endif()

if(gcc_FREESTANDING)
set(_cmd ${_cmd} -ffreestanding)
endif()

if(gcc_NOSTDLIB)
set(_cmd ${_cmd} -nostdlib)
endif()

set(_cmd
${GCC} -o ${gcc_OUTPUT} -c ${gcc_INPUT}
${_bits_arg}
$<$<BOOL:gcc_NOEXCEPTIONS>:-fno-exceptions>
$<$<BOOL:gcc_NORTTI>:-fno-rtti>
$<$<BOOL:gcc_WALL>:-Wall>
$<$<BOOL:gcc_WEXTRA>:-Wextra>
$<$<BOOL:gcc_FREESTANDING>:-ffreestanding>
)
foreach(_tmp ${gcc_INPUTS})
get_filename_component(_tmp ${_tmp} ABSOLUTE)
set(_cmd ${_cmd} ${_tmp})
endforeach()

add_custom_command(
OUTPUT ${gcc_OUTPUT}
DEPENDS ${gcc_INPUT}
DEPENDS ${gcc_INPUT} ${gcc_INPUTS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
COMMAND ${CMAKE_COMMAND} -E echo ${_cmd}
COMMAND ${_cmd}
Expand Down
16 changes: 12 additions & 4 deletions gnuld.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
include_guard(GLOBAL)

find_program(GNULD NAMES ld ld.exe)
find_program(LD
NAMES ld ld.exe
DOC "Path to GNU ld"
)

if(NOT EXISTS ${LD})
message(FATAL_ERROR "GNU ld not found")
endif()

find_program(MASM NAMES "ml.exe" "ml64.exe")
function(ld)
set(options MAP LISTING)
set(single_args INPUT OUTPUT FORMAT SYNTAX DEBUG_FORMAT LIST_FILE MAP_FILE)
set(multi_args DEFINES)
cmake_parse_arguments(yasm "${options}" "${single_args}" "${mutli_args}" ${ARGN})

function(ldlink _target _script)
get_filename_component(_script ${_script} ABSOLUTE)

add_custom_command(OUTPUT ${_target}
DEPENDS ${_script}
Expand Down
4 changes: 2 additions & 2 deletions yasm.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

find_program(YASM
yasm NAMES yasm yasm.exe
NAMES yasm yasm.exe
PATHS /usr/bin /bin
DOC "Path to yasm"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ function(yasm)
set(options MAP LISTING)
set(single_args INPUT OUTPUT FORMAT SYNTAX DEBUG_FORMAT LIST_FILE MAP_FILE)
set(multi_args DEFINES)
cmake_parse_arguments(yasm "${options}" "${single_args}" "${mutli_args}" ${ARGN})
cmake_parse_arguments(yasm "${options}" "${single_args}" "${multi_args}" ${ARGN})

set(_output ${yasm_OUTPUT})
get_filename_component(yasm_INPUT ${yasm_INPUT} ABSOLUTE)
Expand Down

0 comments on commit 81b145c

Please sign in to comment.