Skip to content

Commit

Permalink
Use system compiler to build (#516)
Browse files Browse the repository at this point in the history
* Don't use vcpkg clang to build remill in build script

* Don't manually set compiler within CMakeLists.txt & Fix ccache detection

* Simplify ccache usage

Don't use a macro since we just immediately invoke it

* Turn on CMAKE_ENABLE_EXPORTS to fix tests

Not sure exactly why the updated CMake version affected this, but it
did.

See https://cmake.org/cmake/help/latest/variable/CMAKE_ENABLE_EXPORTS.html#variable:CMAKE_ENABLE_EXPORTS

* Bump number of build jobs in Dockerfile
  • Loading branch information
ekilmer authored May 17, 2021
1 parent 76f3725 commit 1b415d6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 93 deletions.
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.14)
include(cmake/vcpkg_helper.cmake)

project(remill)
cmake_minimum_required(VERSION 3.14)
# Setup to use ccache
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/ccache.cmake")

project(remill C CXX ASM)
include(GNUInstallDirs)

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/settings.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/ccache.cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(CTest)

configureCcache()
FindAndSelectClangCompiler()

enable_language(C CXX ASM)

set(REMILL_SOURCE_DIR "${PROJECT_SOURCE_DIR}")

Expand Down Expand Up @@ -322,6 +320,10 @@ install(EXPORT remillTargets
# tests
message("compiler ID ${CMAKE_C_COMPILER_ID}")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
# Tests require enabling exports on binaries
# https://cmake.org/cmake/help/latest/variable/CMAKE_ENABLE_EXPORTS.html#variable:CMAKE_ENABLE_EXPORTS
set(CMAKE_ENABLE_EXPORTS ON)

find_package(Threads REQUIRED)
add_custom_target(test_dependencies)

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ RUN apt-get update && \
FROM deps as build
ARG LLVM_VERSION

WORKDIR /rellic
WORKDIR /remill
COPY ./ ./
RUN ./scripts/build.sh \
--llvm-version ${LLVM_VERSION} \
--prefix /opt/trailofbits \
--extra-cmake-args "-DCMAKE_BUILD_TYPE=Release"

RUN cd remill-build && \
cmake --build . --target test_dependencies && \
CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --verbose --target test && \
cmake --build . --target test_dependencies -- -j $(nproc) && \
CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --verbose --target test -- -j $(nproc) && \
cmake --build . --target install

# Small installation image
Expand Down
35 changes: 12 additions & 23 deletions cmake/ccache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.4)
find_program(ccache_path ccache)
if("${ccache_path}" STREQUAL "ccache_path-NOTFOUND")
message(STATUS "ccache: Not found")
else()
set(CMAKE_C_COMPILER_LAUNCHER "${ccache_path}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${ccache_path}")

macro(configureCcache)
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND
NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")

message(STATUS "ccache: Not supported")

else()
find_program(ccache_path ccache)
if("${ccache_path}" STREQUAL "ccache_path-NOTFOUND")
message(STATUS "ccache: Not found")
else()
set(CMAKE_C_COMPILER_LAUNCHER "${ccache_path}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${ccache_path}")

set(ccache_dir "$ENV{CCACHE_DIR}")
if("${ccache_dir}" STREQUAL "")
set(ccache_dir "$ENV{HOME}/.ccache")
endif()

message(STATUS "ccache: enabled with '${ccache_path}'. The cache folder is located here: '${ccache_dir}'")
endif()
set(ccache_dir "$ENV{CCACHE_DIR}")
if("${ccache_dir}" STREQUAL "")
set(ccache_dir "$ENV{HOME}/.ccache")
endif()
endmacro()

message(STATUS "ccache: enabled with '${ccache_path}'. The cache folder is located here: '${ccache_dir}'")
endif()
58 changes: 0 additions & 58 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
cmake_minimum_required(VERSION 3.2)

function(FindAndSelectClangCompiler)
if(DEFINED ENV{LLVM_INSTALL_PREFIX})
set(LLVM_INSTALL_PREFIX $ENV{LLVM_INSTALL_PREFIX} PARENT_SCOPE)
endif()

if(DEFINED LLVM_INSTALL_PREFIX)
list(APPEND FINDPACKAGE_LLVM_HINTS "${LLVM_INSTALL_PREFIX}/lib/cmake/llvm/")
list(APPEND FINDPACKAGE_LLVM_HINTS "${LLVM_INSTALL_PREFIX}/share/llvm/cmake/")
set(FINDPACKAGE_LLVM_HINTS ${FINDPACKAGE_LLVM_HINTS} PARENT_SCOPE)

message(STATUS "Using LLVM_INSTALL_PREFIX hints for find_package(LLVM): ${FINDPACKAGE_LLVM_HINTS}")
endif()

if(DEFINED WIN32)
set(executable_extension ".exe")
else()
set(executable_extension "")
endif()

# it is important to avoid re-defining these variables if they have been already
# set or you risk ending up in a configure loop!
if(NOT DEFINED CMAKE_C_COMPILER)
if(DEFINED LLVM_INSTALL_PREFIX)
set(CMAKE_C_COMPILER "${LLVM_INSTALL_PREFIX}/bin/clang${executable_extension}"
CACHE PATH "Path to clang binary." FORCE)
else()
set(CMAKE_C_COMPILER "clang" PARENT_SCOPE)
endif()
endif()

if(NOT DEFINED CMAKE_CXX_COMPILER)
if(DEFINED LLVM_INSTALL_PREFIX)
set(CMAKE_CXX_COMPILER "${LLVM_INSTALL_PREFIX}/bin/clang++${executable_extension}"
CACHE PATH "Path to clang++ binary." FORCE)
else()
set(CMAKE_CXX_COMPILER "clang++${executable_extension}" PARENT_SCOPE)
endif()
endif()

if(NOT DEFINED CMAKE_ASM_COMPILER)
if(DEFINED LLVM_INSTALL_PREFIX)
set(CMAKE_ASM_COMPILER "${LLVM_INSTALL_PREFIX}/bin/clang++${executable_extension}"
CACHE PATH "Path to assembler (aka clang) binary." FORCE)
else()
set(CMAKE_ASM_COMPILER ${CMAKE_CXX_COMPILER} PARENT_SCOPE)
endif()
endif()

if(NOT DEFINED CMAKE_LLVM_LINK)
if(DEFINED LLVM_INSTALL_PREFIX)
set(CMAKE_LLVM_LINK "${LLVM_INSTALL_PREFIX}/bin/llvm-link${executable_extension}"
CACHE PATH "Path to llvm-link binary." FORCE)
else()
set(CMAKE_LLVM_LINK "llvm-link${executable_extension}" PARENT_SCOPE)
endif()
endif()
endfunction()

function(GetTargetTree output_variable)
if(${ARGC} LESS 1)
message(FATAL_ERROR "Usage: GetTargetTree output_var target1 target2 ...")
Expand Down
2 changes: 0 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ function Configure
cmake \
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-DCMAKE_VERBOSE_MAKEFILE=True \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DVCPKG_ROOT="${DOWNLOAD_DIR}/${LIBRARY_VERSION}" \
${BUILD_FLAGS} \
"${SRC_DIR}"
Expand Down

0 comments on commit 1b415d6

Please sign in to comment.