Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.4.0)
cmake_minimum_required(VERSION 3.5)

cmake_policy(SET CMP0042 OLD) # Fix MACOSX_RPATH.
cmake_policy(SET CMP0048 NEW) # Allow VERSION argument in project().
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW) # No longer implicitly dereference variables.
endif()

set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo)
include(cmake/cable/bootstrap.cmake)
include(CableBuildType)

cable_set_build_type(DEFAULT RelWithDebInfo CONFIGURATION_TYPES Debug Release RelWithDebInfo)

project(EVMJIT VERSION 0.9.0.2 LANGUAGES CXX C)


list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

message(STATUS "EVM JIT ${EVMJIT_VERSION_MAJOR}.${EVMJIT_VERSION_MINOR}.${EVMJIT_VERSION_PATCH}")
Expand Down
1 change: 1 addition & 0 deletions cmake/cable/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea
99 changes: 99 additions & 0 deletions cmake/cable/CableBuildInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Cable: CMake Bootstrap Library.
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

if(cable_build_info_included)
return()
endif()
set(cable_build_info_included TRUE)

include(GNUInstallDirs)

set(cable_buildinfo_template_dir ${CMAKE_CURRENT_LIST_DIR}/buildinfo)

function(cable_add_buildinfo_library)

cmake_parse_arguments("" "" PROJECT_NAME;EXPORT "" ${ARGN})

if(NOT _PROJECT_NAME)
message(FATAL_ERROR "The PROJECT_NAME argument missing")
endif()

# Come up with the target and the C function names.
set(name ${_PROJECT_NAME}-buildinfo)
set(FUNCTION_NAME ${_PROJECT_NAME}_get_buildinfo)

set(output_dir ${CMAKE_CURRENT_BINARY_DIR}/${_PROJECT_NAME})
set(header_file ${output_dir}/buildinfo.h)
set(source_file ${output_dir}/buildinfo.c)

if(CMAKE_CONFIGURATION_TYPES)
set(build_type ${CMAKE_CFG_INTDIR})
else()
set(build_type ${CMAKE_BUILD_TYPE})
endif()

# Find git here to allow the user to provide hints.
find_package(Git)

# Git info target.
#
# This target is named <name>-git and is always built.
# The executed script gitinfo.cmake check git status and updates files
# containing git information if anything has changed.
add_custom_target(
${name}-git
COMMAND ${CMAKE_COMMAND}
-DGIT=${GIT_EXECUTABLE}
-DSOURCE_DIR=${PROJECT_SOURCE_DIR}
-DOUTPUT_DIR=${output_dir}
-P ${cable_buildinfo_template_dir}/gitinfo.cmake
BYPRODUCTS ${output_dir}/gitinfo.txt
)

add_custom_command(
COMMENT "Updating ${name}:"
OUTPUT ${source_file} ${output_dir}/buildinfo.json
COMMAND ${CMAKE_COMMAND}
-DOUTPUT_DIR=${output_dir}
-DPROJECT_NAME=${_PROJECT_NAME}
-DFUNCTION_NAME=${FUNCTION_NAME}
-DPROJECT_VERSION=${PROJECT_VERSION}
-DSYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DSYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}
-DCOMPILER_ID=${CMAKE_CXX_COMPILER_ID}
-DCOMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}
-DBUILD_TYPE=${build_type}
-P ${cable_buildinfo_template_dir}/buildinfo.cmake
DEPENDS
${cable_buildinfo_template_dir}/buildinfo.cmake
${cable_buildinfo_template_dir}/buildinfo.c.in
${cable_buildinfo_template_dir}/buildinfo.json.in
${cable_buildinfo_template_dir}/version.h.in
${name}-git
${output_dir}/gitinfo.txt
)

string(TIMESTAMP TIMESTAMP)
configure_file(${cable_buildinfo_template_dir}/buildinfo.h.in ${header_file})

# Add buildinfo library under given name.
# Make is static and do not build by default until some other target will actually use it.
add_library(${name} STATIC ${source_file} ${header_file})

target_include_directories(${name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
set_target_properties(
${name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${output_dir}
ARCHIVE_OUTPUT_DIRECTORY ${output_dir}
)

if(_EXPORT)
install(TARGETS ${name} EXPORT ${_EXPORT}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

endfunction()
44 changes: 44 additions & 0 deletions cmake/cable/CableBuildType.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Cable: CMake Bootstrap Library.
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.

if(cable_build_type_included)
return()
endif()
set(cable_build_type_included TRUE)

macro(cable_set_build_type)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.
if(PROJECT_SOURCE_DIR)
message(FATAL_ERROR "cable_set_build_type() can be used before project()")
endif()

cmake_parse_arguments(build_type "" DEFAULT CONFIGURATION_TYPES ${ARGN})

if(CMAKE_CONFIGURATION_TYPES)
if(build_type_CONFIGURATION_TYPES)
set(
CMAKE_CONFIGURATION_TYPES
${build_type_CONFIGURATION_TYPES}
CACHE
STRING
"Available configurations for multi-configuration generators"
FORCE
)
endif()
cable_log("Configurations: ${CMAKE_CONFIGURATION_TYPES}")
else()
if(build_type_DEFAULT AND NOT CMAKE_BUILD_TYPE)
set(
CMAKE_BUILD_TYPE
${build_type_DEFAULT}
CACHE STRING
"Build type for single-configuration generators"
FORCE
)
endif()
cable_log("Build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()
endmacro()
157 changes: 157 additions & 0 deletions cmake/cable/CableCompilerSettings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Cable: CMake Bootstrap Library
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.

include(CheckCXXCompilerFlag)

# Adds CXX compiler flag if the flag is supported by the compiler.
#
# This is effectively a combination of CMake's check_cxx_compiler_flag()
# and add_compile_options():
#
# if(check_cxx_compiler_flag(flag))
# add_compile_options(flag)
#
function(cable_add_cxx_compiler_flag_if_supported FLAG)
# Remove leading - or / from the flag name.
string(REGEX REPLACE "^-|/" "" name ${FLAG})
check_cxx_compiler_flag(${FLAG} ${name})
if(${name})
add_compile_options(${FLAG})
endif()

# If the optional argument passed, store the result there.
if(ARGV1)
set(${ARGV1} ${name} PARENT_SCOPE)
endif()
endfunction()


# Configures the compiler with default flags.
macro(cable_configure_compiler)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.

cmake_parse_arguments(cable "NO_CONVERSION_WARNINGS;NO_STACK_PROTECTION;NO_PEDANTIC" "" "" ${ARGN})

if(cable_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "cable_configure_compiler: Unknown options: ${cable_UNPARSED_ARGUMENTS}")
endif()

# Set helper variables recognizing C++ compilers.
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
set(CABLE_COMPILER_GNU TRUE)
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
# This matches both clang and AppleClang.
set(CABLE_COMPILER_CLANG TRUE)
endif()

if(CABLE_COMPILER_GNU OR CABLE_COMPILER_CLANG)
set(CABLE_COMPILER_GNULIKE TRUE)
endif()

if(CABLE_COMPILER_GNULIKE)

if(NOT cable_NO_PEDANTIC)
add_compile_options(-Wpedantic)
endif()

# Enable basing warnings set and treat them as errors.
add_compile_options(-Werror -Wall -Wextra -Wshadow)

if(NOT cable_NO_CONVERSION_WARNINGS)
# Enable conversion warnings if not explicitly disabled.
add_compile_options(-Wconversion -Wsign-conversion)
endif()

# Allow unknown pragmas, we don't want to wrap them with #ifdefs.
add_compile_options(-Wno-unknown-pragmas)

# Stack protection.
check_cxx_compiler_flag(-fstack-protector fstack-protector)
if(fstack-protector)
# The compiler supports stack protection options.
if(cable_NO_STACK_PROTECTION)
# Stack protection explicitly disabled.
# Add "no" flag, because in some configuration the compiler has it enabled by default.
add_compile_options(-fno-stack-protector)
else()
# Try enabling the "strong" variant.
cable_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support)
if(NOT have_stack_protector_strong_support)
# Fallback to standard variant of "strong" not available.
add_compile_options(-fstack-protector)
endif()
endif()
endif()

cable_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)

elseif(MSVC)

# Get rid of default warning level.
string(REPLACE " /W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE " /W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

# Enable basing warnings set and treat them as errors.
add_compile_options(/W4 /WX)

# Allow unknown pragmas, we don't want to wrap them with #ifdefs.
add_compile_options(/wd4068)

endif()

# Option for arch=native.
option(NATIVE "Build for native CPU" OFF)
if(NATIVE)
if(MSVC)
add_compile_options(-arch:AVX)
else()
add_compile_options(-mtune=native -march=native)
endif()
elseif(NOT MSVC)
# Tune for currently most common CPUs.
cable_add_cxx_compiler_flag_if_supported(-mtune=generic)
endif()

# Sanitizers support.
set(SANITIZE OFF CACHE STRING "Build with the specified sanitizer")
if(SANITIZE)
# Set the linker flags first, they are required to properly test the compiler flag.
set(CMAKE_SHARED_LINKER_FLAGS "-fsanitize=${SANITIZE} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=${SANITIZE} ${CMAKE_EXE_LINKER_FLAGS}")

set(test_name have_fsanitize_${SANITIZE})
check_cxx_compiler_flag(-fsanitize=${SANITIZE} ${test_name})
if(NOT ${test_name})
message(FATAL_ERROR "Unsupported sanitizer: ${SANITIZE}")
endif()
add_compile_options(-fno-omit-frame-pointer -fsanitize=${SANITIZE})

set(backlist_file ${PROJECT_SOURCE_DIR}/sanitizer-blacklist.txt)
if(EXISTS ${backlist_file})
check_cxx_compiler_flag(-fsanitize-blacklist=${backlist_file} have_fsanitize-blacklist)
if(have_fsanitize-blacklist)
add_compile_options(-fsanitize-blacklist=${backlist_file})
endif()
endif()
endif()

# Code coverage support.
option(COVERAGE "Build with code coverage support" OFF)
if(COVERAGE)
# Set the linker flags first, they are required to properly test the compiler flag.
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}")

set(CMAKE_REQUIRED_LIBRARIES "--coverage ${CMAKE_REQUIRED_LIBRARIES}")
check_cxx_compiler_flag(--coverage have_coverage)
string(REPLACE "--coverage " "" CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
if(NOT have_coverage)
message(FATAL_ERROR "Coverage not supported")
endif()
add_compile_options(-g --coverage)
endif()

endif()
endmacro()
28 changes: 28 additions & 0 deletions cmake/cable/CablePackage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Cable: CMake Bootstrap Library.
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.

if(cable_package_included)
return()
endif()
set(cable_package_included TRUE)

# Configures CPack to build the archive package.
macro(cable_add_archive_package)
if(WIN32)
set(CPACK_GENERATOR ZIP)
set(CPACK_SOURCE_GENERATOR ZIP)
else()
set(CPACK_GENERATOR TGZ)
set(CPACK_SOURCE_GENERATOR TGZ)
endif()
string(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} system_processor)
set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${PROJECT_VERSION}-${system_name}-${system_processor})
set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PROJECT_NAME}-${PROJECT_VERSION}-source)
set(CPACK_PACKAGE_CHECKSUM SHA256)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE)
unset(system_name)
unset(system_processor)
include(CPack)
endmacro()
31 changes: 31 additions & 0 deletions cmake/cable/CableToolchains.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Cable: CMake Bootstrap Library.
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.

set(cable_toolchain_dir ${CMAKE_CURRENT_LIST_DIR}/toolchains)

function(cable_configure_toolchain)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.

cmake_parse_arguments("" "" "DEFAULT" "" ${ARGN})

set(default_toolchain default)
if(_DEFAULT)
set(default_toolchain ${_DEFAULT})
endif()

set(TOOLCHAIN ${default_toolchain} CACHE STRING "CMake toolchain")

set(toolchain_file toolchains/${TOOLCHAIN}.cmake)
foreach(path ${CMAKE_MODULE_PATH})
if(EXISTS "${path}/${toolchain_file}")
set(toolchain_file "${path}/${toolchain_file}")
break()
endif()
endforeach()

cable_debug("Toolchain file: ${toolchain_file}")
set(CMAKE_TOOLCHAIN_FILE ${toolchain_file} CACHE FILEPATH "CMake toolchain file")
endif()
endfunction()
Loading