Skip to content
Open
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
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ endif()
# set the project name
project(cpfe)

# Setup CMake module path to find our custom modules (like FindLibGCCJIT.cmake)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# GCC Backend Option
option(EDG_ENABLE_GCC_BACKEND "Enable the libgccjit backend" OFF)
if(EDG_ENABLE_GCC_BACKEND)
find_package(LibGCCJIT REQUIRED)
endif()

# Check for attempts to use an in-source build.
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR
Expand Down Expand Up @@ -82,6 +91,10 @@ if(NOT WIN32)
set(EDG_BUILD_LIB TRUE CACHE BOOL "Enable the EDG library build")
endif()

# Enable Testing
enable_testing()
include(CTest)

# For GCC and Clang provide an (off by default) option for colored output.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down Expand Up @@ -145,3 +158,29 @@ include(${CMAKE_SOURCE_DIR}/cmake/wrapper.cmake)
# Handle wrapping eccp, needed for building the C library, and general
# development
add_edg_wrapper_script(eccp "." ${CMAKE_SOURCE_DIR}/util/eccp.sh)

if(EDG_ENABLE_GCC_BACKEND)
add_subdirectory(tests/gcc_be)
endif()

# --- CPack Integration ---
set(CPACK_PACKAGE_NAME "edg-cpfe")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "EDG C++ Front End (with GCC backend)")
set(CPACK_PACKAGE_VENDOR "Edison Design Group")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")

if(APPLE)
set(CPACK_GENERATOR "DragNDrop;TGZ")
elseif(WIN32)
set(CPACK_GENERATOR "ZIP;WIX")
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(CPACK_GENERATOR "TXZ")
else()
set(CPACK_GENERATOR "DEB;RPM")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "EDG")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libgccjit0 (>= 10.0.0) | libgccjit-10-dev | libgccjit-11-dev | libgccjit-12-dev | libgccjit-13-dev | libgccjit-14-dev")
set(CPACK_RPM_PACKAGE_REQUIRES "libgccjit")
endif()

include(CPack)
68 changes: 68 additions & 0 deletions cmake/FindLibGCCJIT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# FindLibGCCJIT
# -------------

find_path(LibGCCJIT_INCLUDE_DIR
NAMES libgccjit.h
PATHS
/usr/include
/usr/local/include
/opt/homebrew/include
/opt/local/include
"C:/msys64/mingw64/include"
"C:/Program Files/GCC/include"
)

find_library(LibGCCJIT_LIBRARY
NAMES gccjit
PATHS
/usr/lib
/usr/local/lib
/usr/lib64
/usr/lib/x86_64-linux-gnu
/usr/lib/aarch64-linux-gnu
/opt/homebrew/lib
/opt/homebrew/lib/gcc/current
/opt/local/lib
"C:/msys64/mingw64/lib"
"C:/Program Files/GCC/lib"
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibGCCJIT
REQUIRED_VARS LibGCCJIT_LIBRARY LibGCCJIT_INCLUDE_DIR
)

if(LibGCCJIT_FOUND)
set(LibGCCJIT_INCLUDE_DIRS ${LibGCCJIT_INCLUDE_DIR})
set(LibGCCJIT_LIBRARIES ${LibGCCJIT_LIBRARY})

if(NOT TARGET LibGCCJIT::LibGCCJIT)
add_library(LibGCCJIT::LibGCCJIT UNKNOWN IMPORTED)
set_target_properties(LibGCCJIT::LibGCCJIT PROPERTIES
IMPORTED_LOCATION "${LibGCCJIT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LibGCCJIT_INCLUDE_DIR}"
)
endif()

include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${LibGCCJIT_INCLUDE_DIR})

# Inspect header libgccjit.h for feature availability macros
macro(check_libgccjit_feature FEATURE)
check_c_source_compiles("
#include <libgccjit.h>
#ifndef ${FEATURE}
#error \"Feature ${FEATURE} not available\"
#endif
int main() { return 0; }
" ${FEATURE})
endmacro()

check_libgccjit_feature(LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option)
check_libgccjit_feature(LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option)
check_libgccjit_feature(LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast)
check_libgccjit_feature(LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector)
check_libgccjit_feature(LIBGCCJIT_HAVE_gcc_jit_version)
endif()

mark_as_advanced(LibGCCJIT_INCLUDE_DIR LibGCCJIT_LIBRARY)
Loading