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

# Check for attempts to use an in-source build.
if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR
"In-source builds are not supported: please specify a build "
"directory with -B or use a one of the available presets.")
endif()

# Set a common directory for "binaries"
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -89,19 +96,37 @@ set(EDG_EAGER_REBUILD_LIB FALSE CACHE BOOL
# Support for 32-bit build
set(32BIT_BUILD FALSE CACHE BOOL "Build cpfe as a 32-bit executable")

# Detect the defaults (macro configuration, EDG_BASE, etc.) for this host and
# compiler, used when a configuration doesn't specify them.
include(${CMAKE_SOURCE_DIR}/cmake/host-defaults.cmake)
detect_host_defaults()

# Include and initialize supporting logic for EDG cmake macro configurations.
include(${CMAKE_SOURCE_DIR}/cmake/macro-conf.cmake)
init_macro_configuration_support()

# Resolve EDG_BASE, preferring the environment over the host default. The
# result is exported by environment.sh for use by eccp.
if(NOT "$ENV{EDG_BASE}" STREQUAL "")
set(EDG_BASE "$ENV{EDG_BASE}" CACHE STRING "The EDG base to use.")
else()
set(EDG_BASE "${EDG_HOST_BASE}" CACHE STRING "The EDG base to use.")
endif()

add_subdirectory(util)
add_subdirectory(src)

if($CACHE{EDG_BUILD_LIB})
if(NOT WIN32)
add_subdirectory(lib_src)
# Check edg_eccp_config/EDG_BASE setup
message(STATUS "Checking for edg_eccp_config in \"$ENV{EDG_BASE}\".")
if(NOT DEFINED ENV{EDG_BASE} OR NOT EXISTS $ENV{EDG_BASE}/edg_eccp_config)
message(STATUS
"Checking for edg_eccp_config in \"$CACHE{EDG_BASE}\".")
if("$CACHE{EDG_BASE}" STREQUAL "")
message(FATAL_ERROR
"There is no default EDG_BASE for this host and compiler; "
"please set EDG_BASE to a folder with an \"edg_eccp_config\".")
elseif(NOT EXISTS "$CACHE{EDG_BASE}/edg_eccp_config")
message(FATAL_ERROR
"Please set EDG_BASE to a folder with an \"edg_eccp_config\".")
endif()
Expand Down
13 changes: 9 additions & 4 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ and additionally provides direct access to tools like `edgy`, `cmake`, and

## Native

When configuring natively, CMake selects the macro configuration
(`EDG_MACRO_CONF`), `EDG_BASE`, and the runtime libraries (`EDG_CPP_RT_LIBS`)
that match the host platform, compiler, and build type, so a plain configure
(such as an IDE's default CMake profile) behaves like the corresponding preset.
Setting any of these explicitly (e.g., with `export EDG_BASE=...` or
`-DEDG_MACRO_CONF=...`) overrides the automatic selection.

### Linux

To get started with Linux-native development, make sure `g++` and `cmake` are
Expand All @@ -71,7 +78,6 @@ It should then be possible to follow the build proceedure above with the
`edg-docker-test` (from the EDG project directory):

```
export EDG_BASE="$PWD/bases/docker/dev-env/gcc"
export EDG_GCC_INCL_SCRAPE=$(edg-scrape-compiler gcc --lang c++ includes)
export EDG_GCC_CINCL_SCRAPE=$(edg-scrape-compiler gcc --lang c includes)
export EDG_GCC_VER_SCRAPE=$(edg-scrape-compiler gcc version)
Expand Down Expand Up @@ -108,7 +114,6 @@ It should then be possible to follow the build proceedure above with the
`edg-docker-test` process (from the EDG project directory):

```
export EDG_BASE="$PWD/bases/cmake-native/macos-arm/clang"
export EDG_CLANG_INCL_SCRAPE=$(edg-scrape-compiler clang --lang c++ includes)
export EDG_CLANG_CINCL_SCRAPE=$(edg-scrape-compiler clang --lang c includes)
export EDG_CLANG_VER_SCRAPE=$(edg-scrape-compiler clang version)
Expand Down Expand Up @@ -147,8 +152,8 @@ edgy
> is not an official testing process that works directly on Windows. Once the
> Bash dependencies are removed, testing directly on Windows should become
> possible. At this point remaining issues will be similar to the challenges
> faced with running tests on MacOS (namely different system tools and different
> system headers).
> faced with running tests on MacOS (namely different system tools and
> different system headers).

To get started with Windows-native development, make sure `msvc`, `python`, and
`cmake` are installed (additionally -- if not using the Visual Studio IDE --
Expand Down
90 changes: 90 additions & 0 deletions cmake/host-defaults.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM
# Exceptions.
# See https://edgcpp.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Defaults derived from the host platform and compiler, so that a configure
# which doesn't use a preset (e.g., an IDE's default CMake profile) makes the
# same selections as the matching preset in CMakePresets.json.

function(detect_host_defaults)
# This function sets up the variables:
# - EDG_HOST_MACRO_CONF: the debug macro configuration for this host and
# compiler (the release configuration, if any, adds a "-release"
# suffix), or "" if none is known.
# - EDG_HOST_BASE: the default EDG_BASE directory, or "" if none is known.
# - EDG_HOST_CPP_RT_LIBS: the default EDG_CPP_RT_LIBS list.
set(macro_conf "")
set(base "")
set(cpp_rt_libs "")
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" processor)

if(APPLE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(processor MATCHES "^(arm64|aarch64)$")
set(macro_conf "macos-arm-clang")
set(base "cmake-native/macos-arm/clang")
set(cpp_rt_libs "macos_arm64")
elseif(processor STREQUAL "x86_64")
set(macro_conf "macos-x86-clang")
set(base "cmake-native/macos-x86_64/clang")
set(cpp_rt_libs "macos_x86_64")
endif()
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# The Linux configurations all target an x86_64 (or, for 32-bit builds,
# i686) host.
if(processor MATCHES "^(x86_64|amd64)$")
if($CACHE{32BIT_BUILD})
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(macro_conf "linux-i686-gcc")
set(base "docker/dev-env/gcc-i686")
set(cpp_rt_libs "linux_i686 win32")
endif()
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(macro_conf "linux-gcc")
set(base "docker/dev-env/gcc")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(macro_conf "linux-clang")
set(base "docker/dev-env/clang")
endif()
if(NOT macro_conf STREQUAL "")
string(CONCAT cpp_rt_libs
"linux_riscv64 linux_riscv32 linux_aarch64 linux_armv7 "
"linux_i686 linux_x86_64 win32 win64")
endif()
endif()
endif()
elseif(WIN32 AND MSVC)
if(processor MATCHES "^(x86_64|amd64)$")
set(macro_conf "windows-msvc")
endif()
endif()

if(NOT base STREQUAL "")
set(base "${CMAKE_SOURCE_DIR}/bases/${base}")
endif()

# Export shared state.
set(EDG_HOST_MACRO_CONF "${macro_conf}" PARENT_SCOPE)
set(EDG_HOST_BASE "${base}" PARENT_SCOPE)
set(EDG_HOST_CPP_RT_LIBS "${cpp_rt_libs}" PARENT_SCOPE)
endfunction()

function(host_macro_configuration result_var build_type)
# Set result_var to the host's macro configuration for build_type, or to ""
# if there isn't one.
set(result "")
if(NOT EDG_HOST_MACRO_CONF STREQUAL "")
set(result "${EDG_HOST_MACRO_CONF}")
string(TOUPPER "${build_type}" build_type)
if(build_type MATCHES "^(RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
string(APPEND result "-release")
endif()
if(NOT IS_DIRECTORY "${CMAKE_SOURCE_DIR}/cmake/macro-conf/${result}")
set(result "")
endif()
endif()
set(${result_var} "${result}" PARENT_SCOPE)
endfunction()
48 changes: 38 additions & 10 deletions cmake/macro-conf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,46 @@ else()
PATHS "${CMAKE_SOURCE_DIR}/dev_tools/bin")
endif()

function(init_macro_configuration_support)
set(default "")

# Migrate "EDG_BASE" to "MACRO_CONF"
if(DEFINED CACHE{EDG_BASE})
message(STATUS "Migrating EDG_BASE -> EDG_MACRO_CONF")
set(default "$CACHE{EDG_BASE}")
unset(EDG_BASE CACHE)
function(resolve_macro_configuration result_var macro_conf build_type)
# Set result_var to macro_conf, or, if that's empty, to the host's macro
# configuration for build_type.
set(result "${macro_conf}")
if(result STREQUAL "")
host_macro_configuration(result "${build_type}")
if(result STREQUAL "")
message(WARNING
"No macro configuration matches this host, compiler, and "
"build type \"${build_type}\"; set EDG_MACRO_CONF or use a "
"preset from CMakePresets.json.")
else()
message(STATUS "Auto-selected macro configuration \"${result}\" for "
"build type \"${build_type}\".")
endif()
endif()
set(${result_var} "${result}" PARENT_SCOPE)
endfunction()

set(EDG_MACRO_CONF ${default}
CACHE STRING "The debug macro configuration to use")
function(init_macro_configuration_support)
# An empty macro configuration selects the one matching the host platform,
# compiler, and build type. The selections are exported as
# CACHE{EDG_MACRO_CONF} (single-configuration generators) or
# CACHE{EDG_DEBUG_MACRO_CONF} and CACHE{EDG_RELEASE_MACRO_CONF}
# (multi-configuration generators).
if(CMAKE_CONFIGURATION_TYPES)
resolve_macro_configuration(debug_conf "$CACHE{EDG_DEBUG_MACRO_CONF}"
"Debug")
resolve_macro_configuration(release_conf
"$CACHE{EDG_RELEASE_MACRO_CONF}" "Release")
set(EDG_DEBUG_MACRO_CONF "${debug_conf}" CACHE STRING
"The macro configuration for debug builds")
set(EDG_RELEASE_MACRO_CONF "${release_conf}" CACHE STRING
"The macro configuration for release builds")
else()
resolve_macro_configuration(conf "${EDG_MACRO_CONF}"
"${CMAKE_BUILD_TYPE}")
set(EDG_MACRO_CONF "${conf}" CACHE STRING
"The macro configuration for the build")
endif()
endfunction()

function(process_macro_configuration_setup target macro_conf)
Expand Down
2 changes: 2 additions & 0 deletions cmake/macro-conf/macos-arm-clang-release/cpfe-cp.cmakedef
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto Generated Default File
import <default/cpfe-cp>
2 changes: 2 additions & 0 deletions cmake/macro-conf/macos-arm-clang/cpfe-cp.cmakedef
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto Generated Default File
import <default/cpfe-cp>
6 changes: 4 additions & 2 deletions cmake/wrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ string(JOIN "\n" static_env
"export EDG_MUNCH_PATH=\"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edg_munch\""
"export EDG_DECODE_PATH=\"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edg_decode\""
"export EDG_PRELINK_PATH=\"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edg_prelink\""
"export ECCP=\"${CMAKE_SOURCE_DIR}/util/eccp.sh\"")
"export ECCP=\"${CMAKE_SOURCE_DIR}/util/eccp.sh\""
"export EDG_BASE=\"$CACHE{EDG_BASE}\"")

string(JOIN "\n" lazy_static_env
"export CPFE=\"\${CPFE:-${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cpfe}\""
Expand All @@ -22,7 +23,8 @@ string(JOIN "\n" lazy_static_env
"export EDG_MUNCH_PATH=\"\${EDG_MUNCH_PATH:-${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edg_munch}\""
"export EDG_DECODE_PATH=\"\${EDG_DECODE_PATH:-${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edg_decode}\""
"export EDG_PRELINK_PATH=\"\${EDG_PRELINK_PATH:-${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/edg_prelink}\""
"export ECCP=\"\${ECCP:-${CMAKE_SOURCE_DIR}/util/eccp.sh}\"")
"export ECCP=\"\${ECCP:-${CMAKE_SOURCE_DIR}/util/eccp.sh}\""
"export EDG_BASE=\"\${EDG_BASE:-$CACHE{EDG_BASE}}\"")

FILE(WRITE ${CMAKE_BINARY_DIR}/environment.sh "${static_env}\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/.envrc
Expand Down
2 changes: 1 addition & 1 deletion lib_src/cmake/lib_build_platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Define and expand an EDG_CPP_RT_LIBS cache variable storing the list of
# enabled edg-cpp-rt libraries.
set(EDG_CPP_RT_LIBS "" CACHE STRING
set(EDG_CPP_RT_LIBS "${EDG_HOST_CPP_RT_LIBS}" CACHE STRING
"The EDG C++ runtime libs to include in the default target")
set(EXPANDED_CPP_RT_LIBS $CACHE{EDG_CPP_RT_LIBS})
separate_arguments(EXPANDED_CPP_RT_LIBS)
Expand Down
4 changes: 4 additions & 0 deletions lib_src/cmake/lib_build_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ function(add_edg_cpp_rt_target target_name)
# Create an empty variable to be used as a list of object files.
set(obj_files "")

# Explicitly create the cache directory (needed for some generators -- e.g.,
# Unix Makefiles).
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/${target_name}-cache")

# Add the build for the main object files.
foreach(bare_file_name IN LISTS BARE_FILE_NAMES)
set(src_file_name "${PROJECT_SOURCE_DIR}/${bare_file_name}.c")
Expand Down
Loading