Skip to content

Commit

Permalink
Beta 2 release
Browse files Browse the repository at this point in the history
Co-authored-by: John F. Carr <[email protected]>
Co-authored-by: Angelina Lee <[email protected]>
Co-authored-by: Grace Yin <[email protected]>
  • Loading branch information
4 people committed Jul 10, 2020
1 parent 6d958bd commit 30f280f
Show file tree
Hide file tree
Showing 58 changed files with 16,528 additions and 108 deletions.
213 changes: 213 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# CMake build for Cheetah.

cmake_minimum_required(VERSION 3.4.3)

if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()

# Add path for custom cheetah modules.
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
${CMAKE_MODULE_PATH}
)

# Check if cheetah is built as a standalone project.
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR CHEETAH_STANDALONE_BUILD)
project(cheetah CXX C)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(PACKAGE_NAME cheetah)
set(PACKAGE_VERSION 9.0.1)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "[email protected]")

# Find the LLVM sources and simulate LLVM CMake options.
include(HandleOutOfTreeLLVM)
endif()

# Require out of source build.
include(MacroEnsureOutOfSourceBuild)
MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
"${PROJECT_NAME} requires an out of source build. Please create a separate
build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
)

#===============================================================================
# Setup CMake Options
#===============================================================================
include(CMakeDependentOption)
include(HandleCompilerRT)

# Basic options ---------------------------------------------------------------
option(CHEETAH_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF)
option(CHEETAH_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
option(CHEETAH_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)

option(CHEETAH_INCLUDE_TESTS "Generate build targets for the cheetah unit tests." ${LLVM_INCLUDE_TESTS})
set(CHEETAH_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
"Define suffix of library directory name (32/64)")
option(CHEETAH_INSTALL_LIBRARY "Install the cheetah library." ON)
set(CHEETAH_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
set(CHEETAH_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
set(CHEETAH_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")

option(CHEETAH_ENABLE_SHARED "Build cheetah as a shared library." ON)
option(CHEETAH_ENABLE_STATIC "Build cheetah as a static library." ON)

cmake_dependent_option(CHEETAH_INSTALL_STATIC_LIBRARY
"Install the static cheetah library." ON
"CHEETAH_ENABLE_STATIC;CHEETAH_INSTALL_LIBRARY" OFF)
cmake_dependent_option(CHEETAH_INSTALL_SHARED_LIBRARY
"Install the shared cheetah library." ON
"CHEETAH_ENABLE_SHARED;CHEETAH_INSTALL_LIBRARY" OFF)

set(CHEETAH_ABI_VERSION "1" CACHE STRING "ABI version of cheetah. Defaults to 1.")

if (NOT CHEETAH_ENABLE_SHARED AND NOT CHEETAH_ENABLE_STATIC)
message(FATAL_ERROR "cheetah must be built as either a shared or static library.")
endif()

# Target options --------------------------------------------------------------
set(CHEETAH_SYSROOT "" CACHE STRING "Use alternate sysroot.")
set(CHEETAH_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
set(CHEETAH_MIN_OSX_VERSION 10.9)

#===============================================================================
# Configure System
#===============================================================================

set(CHEETAH_COMPILER ${CMAKE_CXX_COMPILER})
set(CHEETAH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CHEETAH_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

if (LLVM_LIBRARY_OUTPUT_INTDIR AND PACKAGE_VERSION)
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
${PACKAGE_VERSION})
# Setup the paths where cheetah runtime and headers should be stored.
set(CHEETAH_OUTPUT_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION})
set(CHEETAH_INSTALL_PREFIX lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})

if (NOT APPLE)
set(CHEETAH_LIBRARY_DIR ${CHEETAH_OUTPUT_DIR}/lib/${LLVM_DEFAULT_TARGET_TRIPLE})
set(CHEETAH_LIBRARY_INSTALL_DIR ${CHEETAH_INSTALL_PREFIX}/lib/${LLVM_DEFAULT_TARGET_TRIPLE})
if (CHEETAH_LIBDIR_SUFFIX)
string(APPEND CHEETAH_LIBRARY_DIR /${CHEETAH_LIBDIR_SUFFIX})
string(APPEND CHEETAH_LIBRARY_INSTALL_DIR /${CHEETAH_LIBDIR_SUFFIX})
endif()
else()
if(NOT DEFINED CHEETAH_OS_DIR)
string(TOLOWER ${CMAKE_SYSTEM_NAME} CHEETAH_OS_DIR)
endif()
set(CHEETAH_LIBRARY_DIR ${CHEETAH_OUTPUT_DIR}/lib/${CHEETAH_OS_DIR})
set(CHEETAH_LIBRARY_INSTALL_DIR ${CHEETAH_INSTALL_PREFIX}/lib/${CHEETAH_OS_DIR})
endif()

set(CHEETAH_HEADER_DIR ${CHEETAH_OUTPUT_DIR}/include)
set(CHEETAH_HEADER_INSTALL_DIR ${CHEETAH_INSTALL_PREFIX}/include)
else()
set(CHEETAH_OUTPUT_DIR ${CHEETAH_BINARY_DIR} CACHE PATH
"Path where built cheetah library should be stored.")
set(CHEETAH_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH
"Path where built cheetah library should be installed.")
set(CHEETAH_LIBRARY_DIR ${CHEETAH_OUTPUT_DIR}/lib${CHEETAH_LIBDIR_SUFFIX})
set(CHEETAH_LIBRARY_INSTALL_DIR ${CHEETAH_INSTALL_PREFIX}/lib${CHEETAH_LIBDIR_SUFFIX})

set(CHEETAH_HEADER_DIR ${CHEETAH_OUTPUT_DIR}/include)
set(CHEETAH_HEADER_INSTALL_DIR ${CHEETAH_INSTALL_PREFIX}/include)
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CHEETAH_LIBRARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CHEETAH_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CHEETAH_LIBRARY_DIR})

set(CHEETAH_C_FLAGS "")
set(CHEETAH_CXX_FLAGS "")
set(CHEETAH_COMPILE_FLAGS "")
if (APPLE)
list(APPEND CHEETAH_COMPILE_FLAGS -mmacosx-version-min=${CHEETAH_MIN_OSX_VERSION})
endif()
set(CHEETAH_COMPILE_DEFS "")
set(CHEETAH_LINK_FLAGS "")
set(CHEETAH_LIBRARIES "")

# Include macros for adding and removing cheetah flags.
include(HandleCheetahFlags)

#===============================================================================
# Setup Compiler Flags
#===============================================================================

# Configure target flags
if(CHEETAH_TARGET_TRIPLE)
add_target_flags("--target=${CHEETAH_TARGET_TRIPLE}")
elseif(CMAKE_CXX_COMPILER_TARGET)
set(CHEETAH_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
endif()
if(CHEETAH_SYSROOT)
add_target_flags("--sysroot=${CHEETAH_SYSROOT}")
elseif(CMAKE_SYSROOT)
set(CHEETAH_SYSROOT "${CMAKE_SYSROOT}")
endif()
if(CHEETAH_GCC_TOOLCHAIN)
add_target_flags("--gcc-toolchain=${CHEETAH_GCC_TOOLCHAIN}")
elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
set(CHEETAH_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
endif()

if (CHEETAH_TARGET_TRIPLE)
set(TARGET_TRIPLE "${CHEETAH_TARGET_TRIPLE}")
endif()

# Configure compiler.
include(config-ix)

if (CHEETAH_USE_COMPILER_RT)
list(APPEND CHEETAH_LINK_FLAGS "--rtlib=compiler-rt")
endif()

# Get warning flags
add_compile_flags_if_supported(-Wall)

if (CHEETAH_ENABLE_WERROR)
add_compile_flags_if_supported(-Werror)
else()
add_compile_flags_if_supported(-Wno-error)
endif()

# The spawn_main symbol in cheetah is undefined. This routine
# corresponds to the entry point of the compiled Cilk program.
set(CHEETAH_HAS_UNDEFINED_SYMBOLS ON)

if (CHEETAH_HAS_UNDEFINED_SYMBOLS)
# Need to allow unresolved symbols if this is to work with shared library builds
if (APPLE)
list(APPEND CHEETAH_LINK_FLAGS "-undefined dynamic_lookup")
else()
# Relax this restriction from HandleLLVMOptions
string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
endif()
endif()

string(REPLACE ";" " " CHEETAH_CXX_FLAGS "${CHEETAH_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CHEETAH_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CHEETAH_C_FLAGS}")

#===============================================================================
# Setup Source Code
#===============================================================================

include_directories(runtime)

# Add source code. This also contains all of the logic for deciding linker flags
# soname, etc...
add_subdirectory(include)
add_subdirectory(runtime)

if (CHEETAH_INCLUDE_TESTS)
# TODO: Set up CMake for Cheetah tests.
# add_subdirectory(handcomp_test)
# add_subdirectory(bench)
endif()
23 changes: 23 additions & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
==============================================================================
The OpenCilk runtime is licensed under the MIT License:
==============================================================================
Copyright (c) 2020 Massachusetts Institute of Technology and
Washington University in St. Louis

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal with the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ all:
$(MAKE) -C runtime
$(MAKE) -C handcomp_test
$(MAKE) -C bench
$(MAKE) -C reducer_bench

rebuild:
$(MAKE) -C runtime clean
Expand All @@ -10,11 +11,14 @@ rebuild:
$(MAKE) -C handcomp_test
$(MAKE) -C bench clean
$(MAKE) -C bench
$(MAKE) -C reducer_bench clean
$(MAKE) -C reducer_bench

clean:
$(MAKE) -C handcomp_test clean
$(MAKE) -C bench clean
$(MAKE) -C runtime clean
$(MAKE) -C reducer_bench clean

check:
$(MAKE) -C bench test
Expand Down
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
How to build runtime independently from OpenCilk using Makefiles:
- update COMPILER_BASE variable the config.mk to point to the right path
to /path/to/opencilk-project/build/bin (or where its binaries are installed)
- type 'make'

=======================================

How to build runtime independently from OpenCilk using cmake:
- make a build directory at top level and go into it:
> mkdir build
> cd build
- do the cmake configuration step
> cmake -DCMAKE_BUILD_TYPE=Debug ../
- use cmake to build
> cmake --build . -- -j<num of cores>
Note: you can use CMake flags at the configuration step, like
-DCMAKE_C_COMPILER, -DCMAKE_CXX_COMPILER, -DCMAKE_C_FLAGS, etc.

=======================================

How to link with the runtime independently compiled from OpenCilk:
setup your LIBRARY_PATH and LD_LIBRARY_PATH to point to
/path/to/cheetah/runtime

(that's where you can find libopencilkd.a and libopencilk.so)

Alternatively, the compiler by default will look for header files (such as
cilk/cilk.h) in /path/to/opencilk-project/build/lib/clang/9.0.1/include/
and will look for libraries in
/path/to/opencilk-project/build/lib/clang/9.0.1/lib/<something>/
where <something> encodes the architecture and OS

You can copy the necessary header files and compiled libopencilk.*
to these directories where opencilk-project is installed.

Loading

0 comments on commit 30f280f

Please sign in to comment.