diff --git a/CMakeLists_vcpkg.txt b/CMakeLists_vcpkg.txt index 3ce407255..65840f584 100644 --- a/CMakeLists_vcpkg.txt +++ b/CMakeLists_vcpkg.txt @@ -19,7 +19,8 @@ find_package(remill COMPONENTS VCPKG_DEPS QUIET) include(cmake/vcpkg_helper.cmake) -project(mcsema) +project(mcsema C CXX ASM) + include(GNUInstallDirs) cmake_minimum_required(VERSION 3.14) @@ -65,7 +66,7 @@ endif() # find_package(remill CONFIG REQUIRED) -list(APPEND PROJECT_LIBRARIES remill) +list(APPEND PROJECT_LIBRARIES remill_settings remill) get_target_property(REMILL_INCLUDE_LOCATION remill_settings INTERFACE_INCLUDE_DIRECTORIES) # protobuf diff --git a/cmake/BCCompiler.cmake b/cmake/BCCompiler.cmake index 8c0dfb795..37afae203 100644 --- a/cmake/BCCompiler.cmake +++ b/cmake/BCCompiler.cmake @@ -17,79 +17,30 @@ set(DEFAULT_BC_COMPILER_FLAGS -ffreestanding -fno-common -fno-builtin -fno-exceptions -fno-rtti -fno-asynchronous-unwind-tables -Wno-unneeded-internal-declaration -Wno-unused-function -Wgnu-inline-cpp-without-extern -std=c++14 + -Wno-pass-failed=transform-warning ${EXTRA_BC_SYSROOT} ) -set(CLANG_CXX_EXECUTABLE_NAME "clang++") -set(LLVMLINK_EXECUTABLE_NAME "llvm-link") +find_package(Clang CONFIG REQUIRED) +get_target_property(CLANG_PATH clang LOCATION) +get_target_property(LLVMLINK_PATH llvm-link LOCATION) -if(DEFINED WIN32) - set(CLANG_CXX_EXECUTABLE_NAME "${CLANG_CXX_EXECUTABLE_NAME}.exe") - set(LLVMLINK_EXECUTABLE_NAME "${LLVMLINK_EXECUTABLE_NAME}.exe") -endif() - -if(DEFINED ENV{LLVM_INSTALL_PREFIX}) - message(STATUS "Setting LLVM_INSTALL_PREFIX from the environment variable...") - set(LLVM_INSTALL_PREFIX $ENV{LLVM_INSTALL_PREFIX}) -endif() - -if (DEFINED CXX_COMMON_REPOSITORY_ROOT) - if (NOT DEFINED LLVM_INSTALL_PREFIX) - set(LLVM_INSTALL_PREFIX "${CXX_COMMON_REPOSITORY_ROOT}/llvm" CACHE PATH "Path to LLVM install prefix") - endif() -endif() +file(WRITE "${CMAKE_BINARY_DIR}/emitllvm.test.cpp" "int main(int argc, char* argv[]){return 0;}\n\n") -if (DEFINED LLVM_INSTALL_PREFIX) - message(STATUS "LLVM bin dir: ${LLVM_INSTALL_PREFIX}/bin") - # clang path - find_program(CLANG_PATH - NAMES "${CLANG_CXX_EXECUTABLE_NAME}" - HINTS "${LLVM_INSTALL_PREFIX}/bin" - NO_DEFAULT_PATH - ) +execute_process(COMMAND "${CLANG_PATH}" "-emit-llvm" "-c" "emitllvm.test.cpp" "-o" "emitllvm.test.cpp.bc" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + RESULT_VARIABLE AOUT_IS_NOT_BC + OUTPUT_QUIET ERROR_QUIET +) - # llvm-link path - find_program(LLVMLINK_PATH - NAMES "${LLVMLINK_EXECUTABLE_NAME}" - HINTS "${LLVM_INSTALL_PREFIX}/bin" - NO_DEFAULT_PATH - ) +if(NOT "${AOUT_IS_NOT_BC}" STREQUAL "0") + message(SEND_ERROR "The following compiler is not suitable to generate bitcode: ${CLANG_PATH}") else() - # clang path - if("${CMAKE_CXX_COMPILER}" STREQUAL "${CLANG_CXX_EXECUTABLE_NAME}") - set(CLANG_PATH "${CMAKE_CXX_COMPILER}") - - else() - find_program(CLANG_PATH - NAMES "${CLANG_CXX_EXECUTABLE_NAME}" - PATHS "/usr/bin" "/usr/local/bin" "${LLVM_INSTALL_PREFIX}/bin" "${LLVM_TOOLS_BINARY_DIR}" "C:/Program Files/LLVM/bin" "C:/Program Files (x86)/LLVM/bin" - ) - endif() - - # llvm-link path - find_program(LLVMLINK_PATH - NAMES "${LLVMLINK_EXECUTABLE_NAME}" - PATHS "/usr/bin" "/usr/local/bin" "${LLVM_INSTALL_PREFIX}/bin" "${LLVM_TOOLS_BINARY_DIR}" "C:/Program Files/LLVM/bin" "C:/Program Files (x86)/LLVM/bin" - ) -endif() - -if((NOT "${CLANG_PATH}" MATCHES "CLANG_PATH-NOTFOUND") AND (NOT "${LLVMLINK_PATH}" MATCHES "LLVMLINK_PATH-NOTFOUND")) - file(WRITE "${CMAKE_BINARY_DIR}/emitllvm.test.cpp" "int main(int argc, char* argv[]){return 0;}\n\n") + message(STATUS "The following compiler has been selected to compile the bitcode: ${CLANG_PATH}") + message(STATUS "The following linker has been selected to link the bitcode: ${LLVMLINK_PATH}") - execute_process(COMMAND "${CLANG_PATH}" "-emit-llvm" "-c" "emitllvm.test.cpp" "-o" "emitllvm.test.cpp.bc" - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" - RESULT_VARIABLE AOUT_IS_NOT_BC - OUTPUT_QUIET ERROR_QUIET - ) - - if(NOT "${AOUT_IS_NOT_BC}" STREQUAL "0") - message(SEND_ERROR "The following compiler is not suitable to generate bitcode: ${CLANG_PATH}") - else() - message(STATUS "The following compiler has been selected to compile the bitcode: ${CLANG_PATH}") - - set(CMAKE_BC_COMPILER "${CLANG_PATH}" CACHE PATH "Bitcode Compiler") - set(CMAKE_BC_LINKER "${LLVMLINK_PATH}" CACHE PATH "Bitcode Linker") - endif() + set(CMAKE_BC_COMPILER "${CLANG_PATH}" CACHE PATH "Bitcode Compiler") + set(CMAKE_BC_LINKER "${LLVMLINK_PATH}" CACHE PATH "Bitcode Linker") endif() # diff --git a/cmake/vcpkg_helper.cmake b/cmake/vcpkg_helper.cmake index 765c91538..7c979e2ed 100644 --- a/cmake/vcpkg_helper.cmake +++ b/cmake/vcpkg_helper.cmake @@ -19,10 +19,24 @@ if (NOT USE_SYSTEM_DEPENDENCIES) # Set default triplet to Release VCPKG build unless we can't find it if (NOT DEFINED VCPKG_TARGET_TRIPLET) + set(_project_arch "x64") + if (UNIX) + execute_process(COMMAND uname -m + OUTPUT_VARIABLE _SYSTEM_ARCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + message(WARNING "No detection of architecture for this platform. Assuming x64") + endif() + if (_SYSTEM_ARCH MATCHES "^[Aa][Aa][Rr][Cc][Hh]64$") + set(_project_arch "arm64") + endif() + if (APPLE) - set(_project_vcpkg_triplet "x64-osx-rel") + set(_project_vcpkg_triplet "${_project_arch}-osx-rel") elseif(UNIX) - set(_project_vcpkg_triplet "x64-linux-rel") + set(_project_vcpkg_triplet "${_project_arch}-linux-rel") + elseif(WIN32) + set(_project_vcpkg_triplet "${_project_arch}-windows-static-md-rel") else() message(FATAL_ERROR "Could not detect default release triplet") endif() diff --git a/mcsema/Version/CMakeLists.txt b/mcsema/Version/CMakeLists.txt index 956cf9e52..95bae5db0 100644 --- a/mcsema/Version/CMakeLists.txt +++ b/mcsema/Version/CMakeLists.txt @@ -12,5 +12,8 @@ include("${MCSEMA_SOURCE_DIR}/cmake/git_watcher.cmake") # Create a library out of the compiled post-configure file. add_library(McSemaVersion STATIC ${POST_CONFIGURE_FILE}) +if (NOT DEFINED ENV{TRAILOFBITS_LIBRARIES}) + target_link_libraries(McSemaVersion PRIVATE remill_settings) +endif() target_include_directories(McSemaVersion PUBLIC ${MCSEMA_SOURCE_DIR}) add_dependencies(McSemaVersion check_git_${PROJECT_NAME})