From b641bc2bf0973e41cb2d23a3d171912d01e47624 Mon Sep 17 00:00:00 2001 From: Johannes Blaser Date: Tue, 10 Sep 2024 15:23:38 +0000 Subject: [PATCH] Fixed the build system (again) and exported a more useful SVF CMake package for our use-case --- CMakeLists.txt | 329 +++++++++++------------ cmake/ConfigHdr.cmake.in | 52 ++-- cmake/SVF.pc.cmake.in | 11 +- cmake/SVFConfig.cmake.in | 129 +++------ svf-llvm/CMakeLists.txt | 179 +++++++----- svf-llvm/include/CMakeLists.txt | 1 - svf-llvm/include/SVF-LLVM/CMakeLists.txt | 14 - svf-llvm/lib/CMakeLists.txt | 9 - svf-llvm/lib/GenExtAPI.cmake | 40 --- svf-llvm/tools/AE/CMakeLists.txt | 3 +- svf-llvm/tools/CFL/CMakeLists.txt | 3 +- svf-llvm/tools/CMakeLists.txt | 17 +- svf-llvm/tools/DDA/CMakeLists.txt | 3 +- svf-llvm/tools/Example/CMakeLists.txt | 3 +- svf-llvm/tools/LLVM2SVF/CMakeLists.txt | 3 +- svf-llvm/tools/MTA/CMakeLists.txt | 3 +- svf-llvm/tools/SABER/CMakeLists.txt | 3 +- svf-llvm/tools/WPA/CMakeLists.txt | 4 +- svf/CMakeLists.txt | 52 ++-- svf/include/AE/CMakeLists.txt | 2 - svf/include/AE/Core/CMakeLists.txt | 14 - svf/include/AE/Svfexe/CMakeLists.txt | 14 - svf/include/CFL/CMakeLists.txt | 14 - svf/include/CMakeLists.txt | 12 - svf/include/DDA/CMakeLists.txt | 14 - svf/include/FastCluster/CMakeLists.txt | 14 - svf/include/Graphs/CMakeLists.txt | 14 - svf/include/MSSA/CMakeLists.txt | 14 - svf/include/MTA/CMakeLists.txt | 14 - svf/include/MemoryModel/CMakeLists.txt | 14 - svf/include/SABER/CMakeLists.txt | 14 - svf/include/SVFIR/CMakeLists.txt | 14 - svf/include/Util/CMakeLists.txt | 14 - svf/include/WPA/CMakeLists.txt | 14 - svf/lib/AE/CMakeLists.txt | 2 - svf/lib/AE/Core/CMakeLists.txt | 3 - svf/lib/AE/Svfexe/CMakeLists.txt | 3 - svf/lib/CFL/CMakeLists.txt | 3 - svf/lib/CMakeLists.txt | 12 - svf/lib/DDA/CMakeLists.txt | 3 - svf/lib/FastCluster/CMakeLists.txt | 3 - svf/lib/Graphs/CMakeLists.txt | 3 - svf/lib/MSSA/CMakeLists.txt | 3 - svf/lib/MTA/CMakeLists.txt | 3 - svf/lib/MemoryModel/CMakeLists.txt | 3 - svf/lib/SABER/CMakeLists.txt | 3 - svf/lib/SVFIR/CMakeLists.txt | 3 - svf/lib/Util/CMakeLists.txt | 3 - svf/lib/Util/ExtAPI.cpp | 10 +- svf/lib/WPA/CMakeLists.txt | 3 - 50 files changed, 406 insertions(+), 711 deletions(-) delete mode 100644 svf-llvm/include/CMakeLists.txt delete mode 100644 svf-llvm/include/SVF-LLVM/CMakeLists.txt delete mode 100644 svf-llvm/lib/CMakeLists.txt delete mode 100644 svf-llvm/lib/GenExtAPI.cmake delete mode 100644 svf/include/AE/CMakeLists.txt delete mode 100644 svf/include/AE/Core/CMakeLists.txt delete mode 100644 svf/include/AE/Svfexe/CMakeLists.txt delete mode 100644 svf/include/CFL/CMakeLists.txt delete mode 100644 svf/include/CMakeLists.txt delete mode 100644 svf/include/DDA/CMakeLists.txt delete mode 100644 svf/include/FastCluster/CMakeLists.txt delete mode 100644 svf/include/Graphs/CMakeLists.txt delete mode 100644 svf/include/MSSA/CMakeLists.txt delete mode 100644 svf/include/MTA/CMakeLists.txt delete mode 100644 svf/include/MemoryModel/CMakeLists.txt delete mode 100644 svf/include/SABER/CMakeLists.txt delete mode 100644 svf/include/SVFIR/CMakeLists.txt delete mode 100644 svf/include/Util/CMakeLists.txt delete mode 100644 svf/include/WPA/CMakeLists.txt delete mode 100644 svf/lib/AE/CMakeLists.txt delete mode 100644 svf/lib/AE/Core/CMakeLists.txt delete mode 100644 svf/lib/AE/Svfexe/CMakeLists.txt delete mode 100644 svf/lib/CFL/CMakeLists.txt delete mode 100644 svf/lib/CMakeLists.txt delete mode 100644 svf/lib/DDA/CMakeLists.txt delete mode 100644 svf/lib/FastCluster/CMakeLists.txt delete mode 100644 svf/lib/Graphs/CMakeLists.txt delete mode 100644 svf/lib/MSSA/CMakeLists.txt delete mode 100644 svf/lib/MTA/CMakeLists.txt delete mode 100644 svf/lib/MemoryModel/CMakeLists.txt delete mode 100644 svf/lib/SABER/CMakeLists.txt delete mode 100644 svf/lib/SVFIR/CMakeLists.txt delete mode 100644 svf/lib/Util/CMakeLists.txt delete mode 100644 svf/lib/WPA/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 36c57bb66..671267da3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,18 @@ cmake_minimum_required(VERSION 3.23) -project(SVF - VERSION 3.1 - DESCRIPTION "SVF is a static value-flow analysis tool for LLVM-based languages" - HOMEPAGE_URL "https://github.com/SVF-tools/SVF" - LANGUAGES C CXX -) +project( + SVF + VERSION 3.1 + DESCRIPTION "SVF is a static value-flow analysis tool for LLVM-based languages" + HOMEPAGE_URL "https://github.com/SVF-tools/SVF" + LANGUAGES C CXX) # ================================================================================= # Base configuration # ================================================================================= # Ensure installation directories like ${CMAKE_INSTALL_LIBDIR} are available +include(FetchContent) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -19,9 +20,19 @@ include(CMakePackageConfigHelpers) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF) -set(INSTALL_RPATH_USE_LINK_PATH ON) + +# # Ensure the RPATH is used for the build tree +# set(CMAKE_SKIP_BUILD_RPATH OFF) + +# # Don't use the RPATH during building; only when installing +# set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF) +# set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + +# # Add paths found by linker to RPATH so they're included at install time +# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) + +# Use LLVM's ld.lld linker +add_link_options("-fuse-ld=lld") # ================================================================================= # SVF options & settings @@ -32,158 +43,149 @@ set(SVF_SANITIZE "" CACHE STRING "Create sanitizer build (address)") +# Set whether or not SVF was built as a shared library +set(SVF_SHARED_LIBS ${BUILD_SHARED_LIBS}) + # Configurable (boolean) options for building SVF -option(SVF_COVERAGE "Create coverage build") -option(SVF_WARN_AS_ERROR "Treat warnings as errors when building SVF (default: on)" ON) -option(SVF_EXPORT_DYNAMIC "Export all (not only used) dynamic symbols to dynamic symbol table") -option(SVF_ENABLE_ASSERTIONS "Always enable assertions") -option(SVF_ENABLE_OPAQUE_POINTERS "Build ExtAPI.bc with opaque pointers enabled") - -# Store the build directory for exposing it later; ensure also available in config -set(SVF_ROOT_DIR ${PROJECT_SOURCE_DIR}) -set(SVF_SOURCE_DIR ${PROJECT_SOURCE_DIR}) -set(SVF_BUILD_DIR ${PROJECT_BINARY_DIR}) - -# Set variables to denote where different SVF structures/files are located -set(SVF_CORE_ROOT ${SVF_SOURCE_DIR}/svf) -set(SVF_CORE_SRCS ${SVF_CORE_ROOT}/lib) -set(SVF_CORE_INCLUDES ${SVF_CORE_ROOT}/include) - -set(SVF_LLVM_ROOT ${SVF_SOURCE_DIR}/svf-llvm) -set(SVF_LLVM_SRCS ${SVF_LLVM_ROOT}/lib) -set(SVF_LLVM_TOOLS ${SVF_LLVM_ROOT}/tools) -set(SVF_LLVM_INCLUDES ${SVF_LLVM_ROOT}/include) - -# Set the installation tree structure -set(SVF_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR}) -set(SVF_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}) -set(SVF_INSTALL_PKGDIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -set(SVF_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/SVF) -set(SVF_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/SVF) - -# Set where extapi.bc is compiled and installed to -set(SVF_EXTAPI_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) -set(SVF_EXTAPI_INSTALL_FILE ${CMAKE_INSTALL_LIBDIR}/extapi.bc) - -message(STATUS "Building SVF with configuration: - SVF version: ${SVF_VERSION} - SVF option - create sanitiser build (str): ${SVF_SANITIZE} - SVF option - coverage build: ${SVF_COVERAGE} - SVF option - warnings as errors: ${SVF_WARN_AS_ERROR} - SVF option - unused dynamic symbols: ${SVF_EXPORT_DYNAMIC} - SVF option - enable build assertions: ${SVF_ENABLE_ASSERTIONS} - SVF option - build opaque pointers: ${SVF_ENABLE_OPAQUE_POINTERS}") - -message(STATUS "SVF installation configuration: - SVF_SOURCE_DIR: ${SVF_SOURCE_DIR} - SVF_BUILD_DIR: ${SVF_BUILD_DIR} - - SVF_CORE_ROOT: ${SVF_CORE_ROOT} - SVF_CORE_SRCS: ${SVF_CORE_SRCS} - SVF_CORE_INCLUDES: ${SVF_CORE_INCLUDES} - - SVF_LLVM_ROOT: ${SVF_LLVM_ROOT} - SVF_LLVM_SRCS: ${SVF_LLVM_SRCS} - SVF_LLVM_TOOLS: ${SVF_LLVM_TOOLS} - SVF_LLVM_INCLUDES: ${SVF_LLVM_INCLUDES} - - SVF_INSTALL_BINDIR: ${SVF_INSTALL_BINDIR} - SVF_INSTALL_LIBDIR: ${SVF_INSTALL_LIBDIR} - SVF_INSTALL_CMAKEDIR: ${SVF_INSTALL_CMAKEDIR} - SVF_INSTALL_INCLUDEDIR: ${SVF_INSTALL_INCLUDEDIR} - - SVF_EXTAPI_INSTALL_DIR: ${SVF_EXTAPI_INSTALL_DIR} - SVF_EXTAPI_INSTALL_FILE: ${SVF_EXTAPI_INSTALL_FILE} -") - -message(STATUS "Using CMake build configuration: - Project source dir: ${PROJECT_SOURCE_DIR} - Project binary dir: ${PROJECT_BINARY_DIR} - CMake generator: ${CMAKE_GENERATOR} - CMake C compiler: ${CMAKE_C_COMPILER_ID} - CMake C++ compiler: ${CMAKE_CXX_COMPILER_ID} - CMake current list directory: ${CMAKE_CURRENT_LIST_DIR} - CMake current source directory: ${CMAKE_SOURCE_DIR} - CMake current binary directory: ${CMAKE_BINARY_DIR} - CMake install directory prefix: ${CMAKE_INSTALL_PREFIX}") +option(SVF_COVERAGE "Create coverage build (default: off)") +option(SVF_ASSERTIONS "Enable assertion statements (default: off)") +option(SVF_DEBUG_INFO "Build with debug symbols enabled (default: on)" ON) +option(SVF_WARN_AS_ERROR "Treat warnings as errors during compilation (default: on)" ON) +option(SVF_EXPORT_DYNAMIC "Export all (also unused) symbols to symbol table (default: on)" ON) +option(SVF_NO_OPAQUE_PTRS "Disable opaque pointers when build extapi.bc (use typed-pointers) (default: off)") + +message(STATUS "Using build configuration: + CMake Configuration: + Generator: ${CMAKE_GENERATOR} + C compiler: ${CMAKE_C_COMPILER_ID} + C++ compiler: ${CMAKE_CXX_COMPILER_ID} + Initial C flags: ${CMAKE_C_FLAGS} + Initial C++ flags: ${CMAKE_CXX_FLAGS} + Main source directory: ${SVF_SOURCE_DIR} + Main binary directory: ${SVF_BINARY_DIR} + SVF Configuration: + SVF version: ${SVF_VERSION} + SVF option - sanitiser: ${SVF_SANITIZE} + SVF option - coverage build: ${SVF_COVERAGE} + SVF option - enable assertions: ${SVF_ASSERTIONS} + SVF option - warnings as errors: ${SVF_WARN_AS_ERROR} + SVF option - unused dynamic symbols: ${SVF_EXPORT_DYNAMIC} + SVF option - disable opaque pointers: ${SVF_NO_OPAQUE_PTRS}") # ================================================================================= # Build configuration/settings # ================================================================================= # By default, build SVF and its targets treating all compiler warnings as errors (except deprecations) -add_compile_options("$<$:-Wall>" "$<$:-Werror>" - "$<$:-Wno-deprecated-declarations>") +if(SVF_WARN_AS_ERROR) + message(STATUS "Treating compiler warnings as errors") + add_compile_options(-Wall -Werror) +else() + message(STATUS "Not treating compiler warnings as errors") +endif() + +# Keep assertions enabled if requested (explicitly add -UNDEBUG to undefine NDEBUG because build mode can set it) +if(SVF_ASSERTIONS) + message(STATUS "Enabling assertion statements in compiled code") + add_compile_definitions(UNDEBUG) -# Keep assertions enabled if requested -add_compile_options("$<$:-UNDEBUG>") + # If this is a release build, CMake automatically adds -DNDEBUG, so remove it manually + string(REGEX REPLACE "\-?DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + string(REGEX REPLACE "\-?DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + string(REGEX REPLACE "\-?DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") + string(REGEX REPLACE "\-?DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") +else() + message(STATUS "Disabling assertions statements in compiled code") + add_compile_definitions(NDEBUG) +endif() # Export dynamic symbols if requested (adds "-export-dynamic" to linkers that support it to enable backtraces) -add_link_options("$<$:-rdynamic>") -add_link_options("$<$:-Wl,--export-dynamic>") +if(SVF_EXPORT_DYNAMIC) + message(STATUS "Exporting all symbols (also unused) to dynamic symbol table") + add_link_options(-rdynamic -Wl,--export-dynamic) +else() + message(STATUS "Only exporting used symbols to dynamic symbol table") +endif() # Configure whether a coverage build should be created for SVF (i.e. add runtime instrumentation) -add_compile_options("$<$,$>:-fprofile-arcs>" - "$<$,$>:-ftest-coverage>") -add_link_options("$<$,$>:-fprofile-arcs>" - "$<$,$>:-ftest-coverage>") +if(SVF_COVERAGE) + message(STATUS "Building SVF with coverage instrumentation") + add_compile_options(-fprofile-arcs -ftest-coverage) + add_link_options(-fprofile-arcs -ftest-coverage) +else() + message(STATUS "Building non-coverage build") +endif() # If building with sanitiser, load the given sanitiser mode if(SVF_SANITIZE STREQUAL "address") - add_compile_options("-fno-omit-frame-pointer" "-fsanitize=address") - add_link_options("-fsanitize=address") - message(STATUS "Sanitizer build: ${SVF_SANITIZE}") + message(STATUS "Creating sanitiser build with AddressSanitiser") + add_compile_options(-fno-omit-frame-pointer -fsanitize=address) + add_link_options(-fsanitize=address) elseif(SVF_SANITIZE STREQUAL "thread") - add_compile_options("-fsanitize=thread") - add_link_options("-fsanitize=thread") - message(STATUS "Sanitizer build: ${SVF_SANITIZE}") + message(STATUS "Creating sanitiser build with ThreadSanitiser") + add_compile_options(-fsanitize=thread) + add_link_options(-fsanitize=thread) elseif(NOT SVF_SANITIZE STREQUAL "") - message(FATAL_ERROR "Unknown sanitizer type: ${SVF_SANITIZE}") + message(FATAL_ERROR "Unrecognised sanitiser mode: ${SVF_SANITIZE}") +else() + message(STATUS "Not building with sanitiser") +endif() + +# If enabled, output debugging information +if(SVF_DEBUG_INFO) + message(STATUS "Enabling debugging information in SVF build") + add_compile_options(-g3) + add_link_options(-g3) +else() + message(STATUS "Not enabling debugging information in SVF build") endif() -# Enable debug information so that error reports are much more verbose (when using SVF) -add_compile_options("-g3") -add_link_options("-g3") +# Disable the numerous deprecation warnings +add_compile_options(-Wno-deprecated-declarations) # ================================================================================= # Find & load external Z3 dependencies # ================================================================================= -# Find Z3 and its include directory from the top-level include file; try from CMake package first +# Try finding a system-wide (or local instance with $Z3_DIR) Z3's CMake package to import directly find_package( Z3 CONFIG HINTS ${Z3_DIR} $ENV{Z3_DIR}) + if(Z3_FOUND) - message(STATUS "Found Z3 CMake package: - Z3 Version Major: ${Z3_VERSION_MAJOR} - Z3 Version Minor: ${Z3_VERSION_MINOR} - Z3 Version Patch: ${Z3_VERSION_PATCH} - Z3 Version Tweak: ${Z3_VERSION_TWEAK} - Z3 Version String: ${Z3_VERSION_STRING} - Z3 C Include Directories: ${Z3_C_INCLUDE_DIRS} - Z3 C++ Include Directories: ${Z3_CXX_INCLUDE_DIRS} - Z3 Libraries: ${Z3_LIBRARIES}") + message(STATUS "Found Z3 CMake package (version: ${Z3_VERSION_STRING})") + + # Use the imported target from the Z3 CMake package + set(Z3_IMPORTED_TARGET z3::libz3) else() - find_library( - Z3_LIBRARIES REQUIRED - NAMES z3 - HINTS ${Z3_DIR} ENV Z3_DIR - PATH_SUFFIXES bin lib) - find_path( - Z3_INCLUDES REQUIRED - NAMES z3++.h - HINTS ${Z3_DIR} ENV Z3_DIR - PATH_SUFFIXES include z3) - message(STATUS "Z3 STATUS: - Z3 library file: ${Z3_LIBRARIES} - Z3 include directory: ${Z3_INCLUDES}") - - # Add the Z3 include directory and link the Z3 library to all targets of SVF - set(CMAKE_INSTALL_RPATH ${Z3_INCLUDES}) - include_directories(SYSTEM ${Z3_INCLUDES}) + message(STATUS "Failed to find Z3 CMake package; searching for library & header files") + + # Explicitly try to find libz3.so/libz3.a and the header files + if(SVF_SHARED_LIBS) + find_library(Z3_LIBRARIES libz3.so HINTS ${Z3_DIR} ENV Z3_DIR) + else() + find_library(Z3_LIBRARIES libz3.a HINTS ${Z3_DIR} ENV Z3_DIR) + endif() + + # Try to find any (even different static/shared mode) instances of Z3 as a fall-back + if(NOT Z3_LIBRARIES) + find_library(Z3_LIBRARIES z3 HINTS ${Z3_DIR} ENV Z3_DIR REQUIRED) + endif() + + # Also find Z3's header files + find_path(Z3_INCLUDES z3++.h HINTS ${Z3_DIR} ENV Z3_DIR REQUIRED) + + # If found, manually create a Z3 package to nicely export the location(s) + message(STATUS "Found Z3 libraries (${Z3_LIBRARIES}) and headers (${Z3_INCLUDES})") + add_library(z3::libz3 UNKNOWN IMPORTED) + set_target_properties(z3::libz3 PROPERTIES IMPORTED_LOCATION "${Z3_LIBRARIES}") + set_target_properties(z3::libz3 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Z3_INCLUDES}") + + # Set the imported target + set(Z3_IMPORTED_TARGET z3::libz3) endif() # ================================================================================= @@ -191,34 +193,43 @@ endif() # ================================================================================= # Create config.h based on config.in; export to /include/Util/config.h -file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include) -configure_file(${PROJECT_SOURCE_DIR}/cmake/ConfigHdr.cmake.in ${PROJECT_BINARY_DIR}/include/Util/config.h) +file(MAKE_DIRECTORY "${SVF_BINARY_DIR}/include") +configure_file("${SVF_SOURCE_DIR}/cmake/ConfigHdr.cmake.in" "${SVF_BINARY_DIR}/include/Util/config.h") # ================================================================================= # Test suite configuration & build # ================================================================================= # Check if the test-suite is present, if it is then build bc files and add testing to cmake build -if(EXISTS ${PROJECT_SOURCE_DIR}/Test-Suite) - include_directories(${PROJECT_SOURCE_DIR}/Test-Suite) +if(EXISTS "${SVF_SOURCE_DIR}/Test-Suite") + message(STATUS "Testing subdirectory found; enabling tests") + include_directories("${SVF_SOURCE_DIR}/Test-Suite") enable_testing() add_subdirectory(Test-Suite) include(CTest) +else() + message(STATUS "No testing subdirectory found; not enabling SVF tests") endif() # ================================================================================= -# Include core SVF source trees +# Add the SVF core subdirectory # ================================================================================= - -# Add the actual SVF and SVF-LLVM targets add_subdirectory(svf) + +# ================================================================================= +# Add the SVF LLVM module subdirectory +# ================================================================================= add_subdirectory(svf-llvm) -# Whether RTTI/Exceptions are enabled currently depends on whether the LLVM instance used to build SVF had them enabled; -# since the LLVM instance is found in the "svf-llvm" subdirectory, it sets the below variables in its parent directory -# (i.e. for this CMakeLists.txt) so check them here -add_compile_definitions("$,,-fno-rtti>" - "$,,-fno-exceptions>") +# ================================================================================= +# Include core SVF source trees +# ================================================================================= + +# If LLVM was built without RTTI, disable it for SVF as well to avoid issues +if(NOT ${SVF_ENABLE_RTTI}) + message(STATUS "LLVM was built without RTTI support; disabling RTTI") + add_compile_options(-fno-rtti) +endif() # ================================================================================= # Installation & package configuration @@ -228,52 +239,40 @@ add_compile_definitions("$,,-fno-rtti>" export( EXPORT SVF_EXPORTED_TARGETS NAMESPACE SVF:: - FILE ${PROJECT_BINARY_DIR}/SVFTargets.cmake) + FILE ${SVF_BINARY_DIR}/SVFTargets.cmake) # Generate SVFConfigVersion.cmake write_basic_package_version_file( - ${PROJECT_BINARY_DIR}/SVFConfigVersion.cmake + ${SVF_BINARY_DIR}/SVFConfigVersion.cmake VERSION "${SVF_VERSION_MAJOR}.${SVF_VERSION_MINOR}" COMPATIBILITY AnyNewerVersion) # Generate the package config -configure_file(${PROJECT_SOURCE_DIR}/cmake/SVF.pc.cmake.in ${PROJECT_BINARY_DIR}/SVF.pc @ONLY) +configure_file(${SVF_SOURCE_DIR}/cmake/SVF.pc.cmake.in ${SVF_BINARY_DIR}/SVF.pc @ONLY) # Install the SVFTargets.cmake file along with the package install( EXPORT SVF_EXPORTED_TARGETS FILE SVFTargets.cmake NAMESPACE SVF:: - DESTINATION ${SVF_INSTALL_CMAKEDIR}) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SVF) # Also generate a relocatable package in the install tree -configure_package_config_file( - ${PROJECT_SOURCE_DIR}/cmake/SVFConfig.cmake.in ${PROJECT_BINARY_DIR}/SVFConfig.cmake - INSTALL_DESTINATION ${SVF_INSTALL_CMAKEDIR} - PATH_VARS SVF_INSTALL_BINDIR - SVF_INSTALL_LIBDIR - SVF_INSTALL_CMAKEDIR - SVF_INSTALL_INCLUDEDIR - SVF_EXTAPI_INSTALL_DIR - SVF_EXTAPI_INSTALL_FILE - CMAKE_INSTALL_INCLUDEDIR) +configure_package_config_file(${SVF_SOURCE_DIR}/cmake/SVFConfig.cmake.in ${SVF_BINARY_DIR}/SVFConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SVF) # Actually install the configuration, versioning, and pkg_config files -install(FILES ${PROJECT_BINARY_DIR}/SVFConfigVersion.cmake DESTINATION ${SVF_INSTALL_CMAKEDIR}) -install(FILES ${PROJECT_BINARY_DIR}/SVFConfig.cmake DESTINATION ${SVF_INSTALL_CMAKEDIR}) -install(FILES ${PROJECT_BINARY_DIR}/SVF.pc DESTINATION ${SVF_INSTALL_PKGDIR}) +install(FILES ${SVF_BINARY_DIR}/SVFConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SVF) +install(FILES ${SVF_BINARY_DIR}/SVFConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SVF) +install(FILES ${SVF_BINARY_DIR}/SVF.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) # Install generated configuration header (see `configure_file()`) to top-level include dir of SVF -install(FILES ${PROJECT_BINARY_DIR}/include/Util/config.h DESTINATION ${SVF_INSTALL_INCLUDEDIR}/Util) - -# Package with CPack -include(InstallRequiredSystemLibraries) -include(CPack) +install(FILES ${SVF_BINARY_DIR}/include/Util/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SVF/Util) # Since SVF builds into non-standard directories; symlink the compile commands file( CREATE_LINK - ${PROJECT_BINARY_DIR}/compile_commands.json - ${PROJECT_SOURCE_DIR}/compile_commands.json + ${SVF_BINARY_DIR}/compile_commands.json + ${SVF_SOURCE_DIR}/compile_commands.json COPY_ON_ERROR SYMBOLIC) diff --git a/cmake/ConfigHdr.cmake.in b/cmake/ConfigHdr.cmake.in index 127e82683..2cff424f8 100644 --- a/cmake/ConfigHdr.cmake.in +++ b/cmake/ConfigHdr.cmake.in @@ -1,31 +1,35 @@ -#ifndef CONFIG_H_IN -#define CONFIG_H_IN +#ifndef SVF_CONFIG_H_IN +#define SVF_CONFIG_H_IN -// Directory structure of SVF source tree (could be moved) -#define SVF_ROOT_DIR "@SVF_SOURCE_DIR@" -#define SVF_SOURCE_DIR "@SVF_SOURCE_DIR@" -#define SVF_BUILD_DIR "@CMAKE_BINARY_DIR@" - -// Expose the root directory SVF is installed to -#define SVF_INSTALL_ROOT "@CMAKE_INSTALL_PREFIX@" -#define SVF_INSTALL_BINDIR "@CMAKE_INSTALL_PREFIX@/@SVF_INSTALL_BINDIR@" -#define SVF_INSTALL_LIBDIR "@CMAKE_INSTALL_PREFIX@/@SVF_INSTALL_LIBDIR@" -#define SVF_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_PREFIX@/@SVF_INSTALL_INCLUDEDIR@" +// Expose the SVF version +#define SVF_VERSION "@SVF_VERSION@" -// Expose where (relative to installation root) the ExtAPI bitcode file is -#define SVF_EXTAPI_DIR "@CMAKE_INSTALL_PREFIX@/@SVF_EXTAPI_INSTALL_DIR@" -#define SVF_EXTAPI_FILE "@CMAKE_INSTALL_PREFIX@/@SVF_EXTAPI_INSTALL_FILE@" +// Expose the settings of this SVF build tree +#cmakedefine SVF_COVERAGE +#cmakedefine SVF_ASSERTIONS +#cmakedefine SVF_WARN_AS_ERROR +#cmakedefine SVF_EXPORT_DYNAMIC +#cmakedefine SVF_NO_OPAQUE_PTRS +#cmakedefine SVF_SANITIZE "@SVF_SANITIZE@" -// Build mode used to build SVF +// Also expose some compilation settings and configurations +#define SVF_CXX_STANDARD "@CMAKE_CXX_STANDARD@" #define SVF_BUILD_TYPE "@CMAKE_BUILD_TYPE@" -// Sanitiser mode used for building SVF -#cmakedefine SVF_SANITIZE "@SVF_SANITIZE@" +#cmakedefine SVF_ENABLE_EH +#cmakedefine SVF_ENABLE_RTTI +#cmakedefine SVF_SHARED_LIBS -// Build options used when building SVF -#cmakedefine SVF_COVERAGE -#cmakedefine SVF_WARN_AS_ERROR -#cmakedefine SVF_EXPORT_DYNAMIC -#cmakedefine SVF_ENABLE_ASSERTIONS +// Lastly expose the build and installation directories of SVF +#define SVF_ROOT_DIR "@SVF_SOURCE_DIR@" +#define SVF_BUILD_DIR "@SVF_BINARY_DIR@" +#define SVF_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" +#define SVF_INSTALL_BINDIR "@CMAKE_INSTALL_FULL_BINDIR@" +#define SVF_INSTALL_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@" +#define SVF_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@/SVF" + +// Set location(s) of where extapi.bc was built & installed to +#define SVF_BUILD_EXTAPI_BC "@SVF_BINARY_DIR@/@CMAKE_INSTALL_INCLUDEDIR@/SVF/extapi.bc" +#define SVF_INSTALL_EXTAPI_BC "@CMAKE_INSTALL_FULL_INCLUDEDIR@/SVF/extapi.bc" -#endif // CONFIG_H_IN +#endif // SVF_CONFIG_H_IN diff --git a/cmake/SVF.pc.cmake.in b/cmake/SVF.pc.cmake.in index fbc8e546b..1d960a62a 100644 --- a/cmake/SVF.pc.cmake.in +++ b/cmake/SVF.pc.cmake.in @@ -1,13 +1,10 @@ prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ -sharedlibdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include Name: SVF Description: SVF Points to Analysis Framework Version: @SVF_VERSION@ - -Requires: -Libs: -L${libdir} -L${sharedlibdir} -lSvfCore -lSvfLLVM +Libs: -L${libdir} -lSvfCore -lSvfLLVM Cflags: -I${includedir} diff --git a/cmake/SVFConfig.cmake.in b/cmake/SVFConfig.cmake.in index 8ed8917fa..a12920bca 100644 --- a/cmake/SVFConfig.cmake.in +++ b/cmake/SVFConfig.cmake.in @@ -2,124 +2,65 @@ include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") -# Build and source tree information -set(SVF_ROOT_DIR "@SVF_ROOT_DIR@") -set(SVF_SOURCE_DIR "@SVF_SOURCE_DIR@") -set(SVF_BUILD_DIR "@SVF_BUILD_DIR@") - -set(SVF_CORE_ROOT "@SVF_CORE_ROOT@") -set(SVF_CORE_SRCS "@SVF_CORE_SRCS@") -set(SVF_CORE_INCLUDES "@SVF_CORE_INCLUDES@") - -set(SVF_LLVM_ROOT "@SVF_LLVM_ROOT@") -set(SVF_LLVM_SRCS "@SVF_LLVM_SRCS@") -set(SVF_LLVM_TOOLS "@SVF_LLVM_TOOLS@") -set(SVF_LLVM_INCLUDES "@SVF_LLVM_INCLUDES@") - -# Set the installed structures relative to this package's installation location -set(SVF_INSTALL_BINDIR "@PACKAGE_SVF_INSTALL_BINDIR@") -set(SVF_INSTALL_LIBDIR "@PACKAGE_SVF_INSTALL_LIBDIR@") -set(SVF_INSTALL_CMAKEDIR "@PACKAGE_SVF_INSTALL_CMAKEDIR@") -set(SVF_INSTALL_INCLUDEDIR "@PACKAGE_SVF_INSTALL_INCLUDEDIR@") -set(SVF_INSTALL_EXTAPI_DIR "@PACKAGE_SVF_EXTAPI_INSTALL_DIR@") -set(SVF_INSTALL_EXTAPI_FILE "@PACKAGE_SVF_EXTAPI_INSTALL_FILE@") -set(SVF_INSTALL_TOP_LVL_INCLUDEDIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") +include(CMakeFindDependencyMacro) -# Lastly derive exposed settings about SVF's build configuration +# Expose the settings of this SVF build tree +set(SVF_VERSION "@SVF_VERSION@") set(SVF_SANITIZE "@SVF_SANITIZE@") set(SVF_COVERAGE "@SVF_COVERAGE@") +set(SVF_ASSERTIONS "@SVF_ASSERTIONS@") set(SVF_WARN_AS_ERROR "@SVF_WARN_AS_ERROR@") set(SVF_EXPORT_DYNAMIC "@SVF_EXPORT_DYNAMIC@") -set(SVF_ENABLE_ASSERTIONS "@SVF_ENABLE_ASSERTIONS@") -set(SVF_ENABLE_OPAQUE_POINTERS "@SVF_ENABLE_OPAQUE_POINTERS@") +set(SVF_NO_OPAQUE_PTRS "@SVF_NO_OPAQUE_PTRS@") -# Expose some additional build flags like the C++ version and such +# Also expose some compilation settings and configurations +set(SVF_CXX_STANDARD "@CMAKE_CXXS_STANDARD@") +set(SVF_SHARED_LIBS "@BUILD_SHARED_LIBS@") set(SVF_BUILD_TYPE "@CMAKE_BUILD_TYPE@") set(SVF_ENABLE_RTTI "@SVF_ENABLE_RTTI@") -set(SVF_CXX_STANDARD "@CMAKE_CXX_STANDARD@") -set(SVF_ENABLE_EXCEPTIONS "@SVF_ENABLE_EXCEPTIONS@") - -message(STATUS "Found SVF Package: - SVF_SOURCE_DIR: ${SVF_SOURCE_DIR} - SVF_BUILD_DIR: ${SVF_BUILD_DIR} - - SVF_CORE_ROOT: ${SVF_CORE_ROOT} - SVF_CORE_SRCS: ${SVF_CORE_SRCS} - SVF_CORE_INCLUDES: ${SVF_CORE_INCLUDES} - - SVF_LLVM_ROOT: ${SVF_LLVM_ROOT} - SVF_LLVM_SRCS: ${SVF_LLVM_SRCS} - SVF_LLVM_TOOLS: ${SVF_LLVM_TOOLS} - SVF_LLVM_INCLUDES: ${SVF_LLVM_INCLUDES} - SVF_INSTALL_BINDIR: ${SVF_INSTALL_BINDIR} - SVF_INSTALL_LIBDIR: ${SVF_INSTALL_LIBDIR} - SVF_INSTALL_CMAKEDIR: ${SVF_INSTALL_CMAKEDIR} - SVF_INSTALL_INCLUDEDIR: ${SVF_INSTALL_INCLUDEDIR} - SVF_INSTALL_EXTAPI_DIR: ${SVF_INSTALL_EXTAPI_DIR} - SVF_INSTALL_EXTAPI_FILE: ${SVF_INSTALL_EXTAPI_FILE} - SVF_INSTALL_TOP_LVL_INCLUDEDIR: ${SVF_INSTALL_TOP_LVL_INCLUDEDIR} - - SVF_SANITIZE: ${SVF_SANITIZE} - SVF_COVERAGE: ${SVF_COVERAGE} - SVF_WARN_AS_ERROR: ${SVF_WARN_AS_ERROR} - SVF_EXPORT_DYNAMIC: ${SVF_EXPORT_DYNAMIC} - SVF_ENABLE_ASSERTIONS: ${SVF_ENABLE_ASSERTIONS} - SVF_ENABLE_OPAQUE_POINTERS: ${SVF_ENABLE_OPAQUE_POINTERS} - SVF_BUILD_TYPE: ${SVF_BUILD_TYPE} - SVF_ENABLE_RTTI: ${SVF_ENABLE_RTTI} - SVF_CXX_STANDARD: ${SVF_CXX_STANDARD} - SVF_ENABLE_EXCEPTIONS: ${SVF_EABLE_EXCEPTIONS}") - -# Find Z3 and its include directory from the top-level include file; try from CMake package first +# Try to find Z3 using the same mechanism as in the top-level CMake script find_package( Z3 CONFIG HINTS ${Z3_DIR} $ENV{Z3_DIR}) + if(Z3_FOUND) - message(STATUS "Found Z3 CMake package: - Z3 Version Major: ${Z3_VERSION_MAJOR} - Z3 Version Minor: ${Z3_VERSION_MINOR} - Z3 Version Patch: ${Z3_VERSION_PATCH} - Z3 Version Tweak: ${Z3_VERSION_TWEAK} - Z3 Version String: ${Z3_VERSION_STRING} - Z3 C Include Directories: ${Z3_C_INCLUDE_DIRS} - Z3 C++ Include Directories: ${Z3_CXX_INCLUDE_DIRS} - Z3 Libraries: ${Z3_LIBRARIES}") + # Use the imported target from the Z3 CMake package + set(Z3_IMPORTED_TARGET z3::libz3) else() - find_library( - Z3_LIBRARIES REQUIRED - NAMES z3 - HINTS ${Z3_DIR} ENV Z3_DIR - PATH_SUFFIXES bin lib) - find_path( - Z3_INCLUDES REQUIRED - NAMES z3++.h - HINTS ${Z3_DIR} ENV Z3_DIR - PATH_SUFFIXES include z3) - message(STATUS "Z3 STATUS: - Z3 library file: ${Z3_LIBRARIES} - Z3 include directory: ${Z3_INCLUDES}") - - # Add the Z3 include directory and link the Z3 library to all targets of SVF - set(CMAKE_INSTALL_RPATH ${Z3_INCLUDES}) - include_directories(SYSTEM ${Z3_INCLUDES}) + # Explicitly try to find libz3.so/libz3.a and the header files + if(SVF_SHARED_LIBS) + find_library(Z3_LIBRARIES libz3.so HINTS ${Z3_DIR} ENV Z3_DIR) + else() + find_library(Z3_LIBRARIES libz3.a HINTS ${Z3_DIR} ENV Z3_DIR) + endif() + + # Try to find any (even different static/shared mode) instances of Z3 as a fall-back + if(NOT Z3_LIBRARIES) + find_library(Z3_LIBRARIES z3 HINTS ${Z3_DIR} ENV Z3_DIR REQUIRED) + endif() + + # Also find Z3's header files + find_path(Z3_INCLUDES z3++.h HINTS ${Z3_DIR} ENV Z3_DIR REQUIRED) + + # If found, manually create a Z3 package to nicely export the location(s) + add_library(z3::libz3 UNKNOWN IMPORTED) + set_target_properties(z3::libz3 PROPERTIES IMPORTED_LOCATION "${Z3_LIBRARIES}") + set_target_properties(z3::libz3 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Z3_INCLUDES}") + + # Set the imported target + set(Z3_IMPORTED_TARGET z3::libz3) endif() -include(CMakeFindDependencyMacro) - find_dependency( LLVM CONFIG REQUIRED HINTS "${LLVM_DIR}" - "$ENV{LLVM_DIR}" - PATH_SUFFIXES - "lib" - "lib/cmake" - "lib/cmake/llvm") + "$ENV{LLVM_DIR}") check_required_components("@PROJECT_NAME@") diff --git a/svf-llvm/CMakeLists.txt b/svf-llvm/CMakeLists.txt index 0b6aaca9b..3481984db 100644 --- a/svf-llvm/CMakeLists.txt +++ b/svf-llvm/CMakeLists.txt @@ -1,3 +1,7 @@ +# ================================================================================= +# LLVM package definition and configuration +# ================================================================================= + if(DEFINED LLVM_ROOT OR DEFINED ENV{LLVM_ROOT}) if(NOT DEFINED LLVM_ROOT) set(LLVM_ROOT $ENV{LLVM_ROOT}) @@ -5,9 +9,9 @@ if(DEFINED LLVM_ROOT OR DEFINED ENV{LLVM_ROOT}) message(STATUS "Finding LLVM in custom LLVM root: ${LLVM_ROOT}") if(EXISTS "${LLVM_ROOT}/lib/cmake/llvm") - list(APPEND CMAKE_PREFIX_PATH ${LLVM_ROOT}/lib/cmake/llvm/) + list(APPEND CMAKE_PREFIX_PATH "${LLVM_ROOT}/lib/cmake/llvm/") else() - list(APPEND CMAKE_PREFIX_PATH ${LLVM_ROOT}) + list(APPEND CMAKE_PREFIX_PATH "${LLVM_ROOT}") endif() endif() @@ -20,51 +24,21 @@ find_package( ${LLVM_DIR} $ENV{LLVM_DIR}) -message(STATUS "LLVM STATUS: - Found: ${LLVM_FOUND} - Version: ${LLVM_VERSION} - Definitions: ${LLVM_DEFINITIONS} - Includes: ${LLVM_INCLUDE_DIRS} - Libraries: ${LLVM_LIBRARY_DIRS} - Targets: ${LLVM_TARGETS_TO_BUILD} - Build type: ${LLVM_BUILD_TYPE} - Exceptions: ${LLVM_ENABLE_EH} - RTTI: ${LLVM_ENABLE_RTTI} - Dynamic lib: ${LLVM_LINK_LLVM_DYLIB}") - -# Though not necessary, check if SVF is being built in debug mode & if that matches LLVM -if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT ${LLVM_BUILD_TYPE} STREQUAL "Debug") - message(NOTICE "Building SVF in debug-mode but LLVM was not built in debug-mode; " - "debug information could be incomplete when using SVF from LLVM") -endif() - # Add LLVM's include directories and link directory for all targets defined hereafter separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) -link_directories(${LLVM_LIBRARY_DIRS}) +# link_directories(${LLVM_LIBRARY_DIRS}) add_definitions(${LLVM_DEFINITIONS}) -# Ensure SVF is built with RTTI/exception handling if the used LLVM instance has them enabled +# Ensure SVF is built with RTTI if the used LLVM instance has them enabled set(SVF_ENABLE_RTTI ${LLVM_ENABLE_RTTI} PARENT_SCOPE) -set(SVF_ENABLE_EXCEPTIONS - ${LLVM_ENABLE_EH} - PARENT_SCOPE) -# Check if LLVM was built generating the single libLLVM.so shared library file or as separate static libraries +# If LLVM was built as a single shared library (libLLVM.so), link to that, otherwise to the static libraries if(LLVM_LINK_LLVM_DYLIB) message(STATUS "Linking to LLVM dynamic shared library object") set(llvm_libs LLVM) - - # Set which components to include in the dynamic library to include the new SvfLLVM - if(LLVM_DYLIB_COMPONENTS) - message(STATUS "Appending SvfLLVM to LLVM dynamic library components") - list(APPEND LLVM_DYLIB_COMPONENTS SvfLLVM) - else() - message(STATUS "Adding all;SvfLLVM to LLVM dynamic library components (was unset)") - set(LLVM_DYLIB_COMPONENTS all;SvfLLVM) - endif() else() message(STATUS "Linking to separate LLVM static libraries") llvm_map_components_to_libnames( @@ -83,48 +57,123 @@ else() transformutils) endif() -# Make the "add_llvm_library()" command available and configure LLVM/CMake -list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR}) -include(AddLLVM) +# Find an instance of 'clang' in the found LLVM installation +find_program( + LLVM_CLANG + NAMES clang + HINTS "${LLVM_BINARY_DIR}" + PATH_SUFFIXES "bin" REQUIRED) + +# # Make the "add_llvm_library()" command available and configure LLVM/CMake +# list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR}) +# include(AddLLVM) + +# ================================================================================= +# ExtAPI.bc generation & target definition +# ================================================================================= +set(EXTAPI_SRC_FILE "${CMAKE_CURRENT_LIST_DIR}/lib/extapi.c") +set(EXTAPI_OUT_FILE "${SVF_BINARY_DIR}/lib/extapi.bc") + +if(EXISTS "${EXTAPI_SRC_FILE}") + message(STATUS "Found extapi.c input file at: ${EXTAPI_SRC_FILE}") +else() + message(FATAL_ERROR "Failed to find extapi.c input file: ${EXTAPI_SRC_FILE}") +endif() + +# Set the flags to compile extapi.c with +set(EXTAPI_COMPILE_FLAGS + -w + -S + -c + -fPIC + -std=gnu11 + -emit-llvm + -Xclang + -disable-O0-optnone) + +# If opaque pointers were disabled, add the appropriate flags +if(SVF_NO_OPAQUE_PTRS) + message(STATUS "Building extapi.bc with opaque pointers disabled") + list(APPEND SVF_EXTAPI_FLAGS -Xclang -no-opaque-pointers) +else() + message(STATUS "Building extapi.bc with opaque pointers enabled") +endif() + +# Add a custom command to compile the extapi.bc bitcode file from extapi.c +add_custom_command( + OUTPUT "${EXTAPI_OUT_FILE}" + COMMAND "${LLVM_CLANG}" ${EXTAPI_COMPILE_FLAGS} -o "${EXTAPI_OUT_FILE}" "${EXTAPI_SRC_FILE}" + DEPENDS "${EXTAPI_SRC_FILE}") -# Define the actual SvfLLVM library (use LLVM's functions to automatically link stuff) -add_llvm_library(SvfLLVM) +# Add a custom target that has the custom command as its creation command +add_custom_target(gen_extapi_ir DEPENDS "${EXTAPI_OUT_FILE}") + +# Install the bitcode file as well; install it to /include/SVF/extapi.bc +install(FILES "${EXTAPI_OUT_FILE}" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SVF) + +# ================================================================================= +# Main SVF LLVM library definition +# ================================================================================= + +# Gather all header and source files +file(GLOB_RECURSE SVF_LLVM_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) +file(GLOB_RECURSE SVF_LLVM_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.cpp) + +# Define the actual SvfLLVM library & set the (so)versions for dynamic library exports +add_library(SvfLLVM) add_library(SVF::SvfLLVM ALIAS SvfLLVM) set_target_properties(SvfLLVM PROPERTIES VERSION ${SVF_VERSION} SOVERSION ${SVF_VERSION_MAJOR}) -# Add the public headers as an include directory -target_include_directories(SvfLLVM PRIVATE ${PROJECT_BINARY_DIR}/include) -target_include_directories(SvfLLVM PUBLIC $ - $) +# Add the source files (private) +target_sources(SvfLLVM PRIVATE ${SVF_LLVM_SOURCES}) -# Ensure that the build artifacts are placed into lib/bin/include relative to the top of the build directory -set_target_properties( +# Set the header files as public (so they're exported & installed) +target_sources( + SvfLLVM + PUBLIC FILE_SET + HEADERS + BASE_DIRS + include + FILES + ${SVF_LLVM_HEADERS}) + +# Add the build include tree privately & the local & installed include directories depending on the interface +target_include_directories( SvfLLVM - PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + PRIVATE $ + PUBLIC $ + PUBLIC $) -# Link LLVM's libraries to SvfLLVM, as well as the SVF core library -target_link_libraries(SvfLLVM PUBLIC SvfCore ${llvm_libs} ${Z3_LIBRARIES}) +# Link Z3 privately to SVF (users of SVF don't directly use its Z3 instance) +target_link_libraries(SvfLLVM PRIVATE ${Z3_IMPORTED_TARGET}) -# Add intrinsics_gen target if we're building as part of LLVM source build -if(TARGET intrinsics_gen) - add_dependencies(SvfLLVM intrinsics_gen) -endif() +# Also add Z3 as private system include directories +target_include_directories(SvfLLVM SYSTEM PRIVATE ${Z3_INCLUDES}) -# Sources and headers are defined in the subdirectories -add_subdirectory(lib) -add_subdirectory(include) +# # Ensure that the build artifacts are placed into lib/bin/include relative to the top of the build directory +set_target_properties( + SvfLLVM + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${SVF_BINARY_DIR}/bin + LIBRARY_OUTPUT_DIRECTORY ${SVF_BINARY_DIR}/lib + ARCHIVE_OUTPUT_DIRECTORY ${SVF_BINARY_DIR}/lib) -# Add the targets for compiling the SvfLLVM tool binaries -add_subdirectory(tools) +# Add a dependency of SvfLLVM to the extapi.bc file +add_dependencies(SvfLLVM gen_extapi_ir) -# Install the SvfLLVM shared library and public headers (public headers go in include/SVF-LLVM) +# Link the SVF Core library to this library +target_link_libraries(SvfLLVM PRIVATE SvfCore) + +# Install the different components of the SVF LLVM library install( TARGETS SvfLLVM EXPORT SVF_EXPORTED_TARGETS - LIBRARY DESTINATION ${SVF_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${SVF_INSTALL_LIBDIR} - RUNTIME DESTINATION ${SVF_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} FILE_SET HEADERS - DESTINATION ${SVF_INSTALL_INCLUDEDIR}) + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SVF) + +# ================================================================================= +# Tools +# ================================================================================= +add_subdirectory(tools) diff --git a/svf-llvm/include/CMakeLists.txt b/svf-llvm/include/CMakeLists.txt deleted file mode 100644 index eb7f95cf7..000000000 --- a/svf-llvm/include/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(SVF-LLVM) diff --git a/svf-llvm/include/SVF-LLVM/CMakeLists.txt b/svf-llvm/include/SVF-LLVM/CMakeLists.txt deleted file mode 100644 index e07fdaffa..000000000 --- a/svf-llvm/include/SVF-LLVM/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfLLVM package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfLLVM; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfLLVM - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_LLVM_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf-llvm/lib/CMakeLists.txt b/svf-llvm/lib/CMakeLists.txt deleted file mode 100644 index f15597b62..000000000 --- a/svf-llvm/lib/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfLLVM package -file(GLOB_RECURSE SVF_LLVM_SOURCES *.cpp) -target_sources(SvfLLVM PRIVATE ${SVF_LLVM_SOURCES}) - -# Add the compile command to generate extapi.bc from the extapi.c source file -include(GenExtAPI.cmake) - -# Ensure SvfLLVM depends on extapi.bc to avoid having to build all when building individual tools -add_dependencies(SvfLLVM gen_extapi_ir) diff --git a/svf-llvm/lib/GenExtAPI.cmake b/svf-llvm/lib/GenExtAPI.cmake deleted file mode 100644 index b6cb64df0..000000000 --- a/svf-llvm/lib/GenExtAPI.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# Set base variables and input/output structures -set(SVF_EXTAPI_FLAGS - -w - -S - -c - -fPIC - -std=gnu11 - -emit-llvm - -Xclang - -disable-O0-optnone) - -set(EXTAPI_SRC_FILE "${CMAKE_CURRENT_LIST_DIR}/extapi.c") -set(EXTAPI_BIN_FILE "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/extapi.bc") - -if(NOT ${SVF_ENABLE_OPAQUE_POINTERS}) - list(APPEND SVF_EXTAPI_FLAGS -Xclang -no-opaque-pointers) -endif() - -if(NOT EXISTS "${EXTAPI_SRC_FILE}") - message(FATAL_ERROR "Failed to find ExtAPI source file!") -endif() - -# Find the Clang compiler; should be available through the LLVM instance found earlier -find_program( - LLVM_CLANG - NAMES clang - HINTS "${LLVM_BINARY_DIR}" - PATH_SUFFIXES "bin" REQUIRED) - -# Define a custom command to compile extapi.c to LLVM IR bitcode in extapi.bc (in the build directory) -add_custom_command( - OUTPUT "${EXTAPI_BIN_FILE}" - COMMAND ${LLVM_CLANG} ${SVF_EXTAPI_FLAGS} -o ${EXTAPI_BIN_FILE} ${EXTAPI_SRC_FILE} - DEPENDS ${EXTAPI_SRC_FILE}) - -# Add a custom target for generating the LLVM bytecode file (and add it to the default build targets) -add_custom_target(gen_extapi_ir ALL DEPENDS "${EXTAPI_BIN_FILE}") - -# Install the bitcode file as well; install it to /lib/extapi.bc -install(FILES "${EXTAPI_BIN_FILE}" DESTINATION "${SVF_INSTALL_LIBDIR}") diff --git a/svf-llvm/tools/AE/CMakeLists.txt b/svf-llvm/tools/AE/CMakeLists.txt index 85abf9b00..e6f8d2485 100644 --- a/svf-llvm/tools/AE/CMakeLists.txt +++ b/svf-llvm/tools/AE/CMakeLists.txt @@ -1,2 +1 @@ -add_llvm_executable(ae ae.cpp) -target_link_libraries(ae PUBLIC ${llvm_libs} SvfLLVM) \ No newline at end of file +add_executable(ae ae.cpp) diff --git a/svf-llvm/tools/CFL/CMakeLists.txt b/svf-llvm/tools/CFL/CMakeLists.txt index 489cbb573..c9cdf995f 100644 --- a/svf-llvm/tools/CFL/CMakeLists.txt +++ b/svf-llvm/tools/CFL/CMakeLists.txt @@ -1,2 +1 @@ -add_llvm_executable(cfl cfl.cpp) -target_link_libraries(cfl PUBLIC ${llvm_libs} SvfLLVM) \ No newline at end of file +add_executable(cfl cfl.cpp) diff --git a/svf-llvm/tools/CMakeLists.txt b/svf-llvm/tools/CMakeLists.txt index e10f91a27..8644d2089 100644 --- a/svf-llvm/tools/CMakeLists.txt +++ b/svf-llvm/tools/CMakeLists.txt @@ -20,14 +20,17 @@ set(ALL_TOOLS foreach(_tool IN LISTS ALL_TOOLS) set_target_properties( ${_tool} - PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" - LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}" - ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") - target_include_directories(${_tool} PRIVATE "$") + PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${SVF_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" + LIBRARY_OUTPUT_DIRECTORY "${SVF_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}" + ARCHIVE_OUTPUT_DIRECTORY "${SVF_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") + + target_include_directories(${_tool} PRIVATE "$") + target_link_libraries(${_tool} PRIVATE ${llvm_libs} SVF::SvfCore SVF::SvfLLVM) + install( TARGETS ${_tool} EXPORT SVF_EXPORTED_TARGETS - RUNTIME DESTINATION "${SVF_INSTALL_BINDIR}" - LIBRARY DESTINATION "${SVF_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${SVF_INSTALL_LIBDIR}") + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") endforeach() diff --git a/svf-llvm/tools/DDA/CMakeLists.txt b/svf-llvm/tools/DDA/CMakeLists.txt index edd1152c2..d15208170 100644 --- a/svf-llvm/tools/DDA/CMakeLists.txt +++ b/svf-llvm/tools/DDA/CMakeLists.txt @@ -1,2 +1 @@ -add_llvm_executable(dvf dda.cpp) -target_link_libraries(dvf PUBLIC ${llvm_libs} SvfLLVM) \ No newline at end of file +add_executable(dvf dda.cpp) diff --git a/svf-llvm/tools/Example/CMakeLists.txt b/svf-llvm/tools/Example/CMakeLists.txt index 9b444bb05..6ba2d258b 100644 --- a/svf-llvm/tools/Example/CMakeLists.txt +++ b/svf-llvm/tools/Example/CMakeLists.txt @@ -1,2 +1 @@ -add_llvm_executable(svf-ex svf-ex.cpp) -target_link_libraries(svf-ex PUBLIC ${llvm_libs} SvfLLVM) \ No newline at end of file +add_executable(svf-ex svf-ex.cpp) diff --git a/svf-llvm/tools/LLVM2SVF/CMakeLists.txt b/svf-llvm/tools/LLVM2SVF/CMakeLists.txt index e838dc05f..d20bf614f 100644 --- a/svf-llvm/tools/LLVM2SVF/CMakeLists.txt +++ b/svf-llvm/tools/LLVM2SVF/CMakeLists.txt @@ -1,2 +1 @@ -add_llvm_executable(llvm2svf llvm2svf.cpp) -target_link_libraries(llvm2svf PUBLIC ${llvm_libs} SvfLLVM) +add_executable(llvm2svf llvm2svf.cpp) diff --git a/svf-llvm/tools/MTA/CMakeLists.txt b/svf-llvm/tools/MTA/CMakeLists.txt index 0508d95cf..06dac4b10 100644 --- a/svf-llvm/tools/MTA/CMakeLists.txt +++ b/svf-llvm/tools/MTA/CMakeLists.txt @@ -1,2 +1 @@ -add_llvm_executable(mta mta.cpp LockResultValidator.cpp MTAResultValidator.cpp MTAAnnotator.cpp) -target_link_libraries(mta PUBLIC ${llvm_libs} SvfLLVM) +add_executable(mta LockResultValidator.cpp mta.cpp MTAAnnotator.cpp MTAResultValidator.cpp) diff --git a/svf-llvm/tools/SABER/CMakeLists.txt b/svf-llvm/tools/SABER/CMakeLists.txt index a4246a24e..ec8bf5650 100644 --- a/svf-llvm/tools/SABER/CMakeLists.txt +++ b/svf-llvm/tools/SABER/CMakeLists.txt @@ -1,2 +1 @@ -add_llvm_executable(saber saber.cpp) -target_link_libraries(saber PUBLIC ${llvm_libs} SvfLLVM) \ No newline at end of file +add_executable(saber saber.cpp) diff --git a/svf-llvm/tools/WPA/CMakeLists.txt b/svf-llvm/tools/WPA/CMakeLists.txt index 4a99b53a3..808b5c51a 100644 --- a/svf-llvm/tools/WPA/CMakeLists.txt +++ b/svf-llvm/tools/WPA/CMakeLists.txt @@ -1,5 +1,5 @@ set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -add_llvm_executable(wpa wpa.cpp) -target_link_libraries(wpa PUBLIC ${llvm_libs} SvfLLVM Threads::Threads) +add_executable(wpa wpa.cpp) +target_link_libraries(wpa PUBLIC Threads::Threads) diff --git a/svf/CMakeLists.txt b/svf/CMakeLists.txt index 9ca5bc0f9..38938d253 100644 --- a/svf/CMakeLists.txt +++ b/svf/CMakeLists.txt @@ -1,31 +1,51 @@ -# Define the core library +# Gather all header and source files +file(GLOB_RECURSE SVF_CORE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) +file(GLOB_RECURSE SVF_CORE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.cpp) + +# Define the core library itself & set the (so)version for dynamic library exports add_library(SvfCore) +add_library(SVF::SvfCore ALIAS SvfCore) set_target_properties(SvfCore PROPERTIES VERSION ${SVF_VERSION} SOVERSION ${SVF_VERSION_MAJOR}) -# Add the public headers as an include directory -target_include_directories(SvfCore PRIVATE ${PROJECT_BINARY_DIR}/include) -target_include_directories(SvfCore PUBLIC $ - $) +# Add the source files (private) +target_sources(SvfCore PRIVATE ${SVF_CORE_SOURCES}) + +# Set the header files as public (so they're exported & installed) +target_sources( + SvfCore + PUBLIC FILE_SET + HEADERS + BASE_DIRS + include + FILES + ${SVF_CORE_HEADERS}) -target_link_libraries(SvfCore PUBLIC ${Z3_LIBRARIES}) +# Add the include directories (for build & install time); also add the current build dir as an include dir +target_include_directories( + SvfCore + PRIVATE $ + PUBLIC $ + PUBLIC $) -# Ensure that the build artifacts are placed into lib/bin/include relative to the top of the build directory +# Link Z3 privately to SVF (users of SVF don't directly use its Z3 instance) +target_link_libraries(SvfCore PRIVATE ${Z3_IMPORTED_TARGET}) + +# Also add Z3 as private system include directories +target_include_directories(SvfCore SYSTEM PRIVATE ${Z3_INCLUDES}) + +# # Ensure that the build artifacts are placed into lib/bin/include relative to the top of the build directory set_target_properties( SvfCore PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) -# Sources and headers are defined in the subdirectories -add_subdirectory(include) -add_subdirectory(lib) - -# Set the installation configuration for the SvfCore package (relative to install prefix) +# Install the different components of the SVF Core library install( TARGETS SvfCore EXPORT SVF_EXPORTED_TARGETS - LIBRARY DESTINATION ${SVF_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${SVF_INSTALL_LIBDIR} - RUNTIME DESTINATION ${SVF_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} FILE_SET HEADERS - DESTINATION ${SVF_INSTALL_INCLUDEDIR}) + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SVF) diff --git a/svf/include/AE/CMakeLists.txt b/svf/include/AE/CMakeLists.txt deleted file mode 100644 index 00fe4bacd..000000000 --- a/svf/include/AE/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(Core) -add_subdirectory(Svfexe) diff --git a/svf/include/AE/Core/CMakeLists.txt b/svf/include/AE/Core/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/AE/Core/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/AE/Svfexe/CMakeLists.txt b/svf/include/AE/Svfexe/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/AE/Svfexe/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/CFL/CMakeLists.txt b/svf/include/CFL/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/CFL/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/CMakeLists.txt b/svf/include/CMakeLists.txt deleted file mode 100644 index 5a321dd6b..000000000 --- a/svf/include/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_subdirectory(AE) -add_subdirectory(CFL) -add_subdirectory(DDA) -add_subdirectory(FastCluster) -add_subdirectory(Graphs) -add_subdirectory(MemoryModel) -add_subdirectory(MSSA) -add_subdirectory(MTA) -add_subdirectory(SABER) -add_subdirectory(SVFIR) -add_subdirectory(Util) -add_subdirectory(WPA) diff --git a/svf/include/DDA/CMakeLists.txt b/svf/include/DDA/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/DDA/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/FastCluster/CMakeLists.txt b/svf/include/FastCluster/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/FastCluster/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/Graphs/CMakeLists.txt b/svf/include/Graphs/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/Graphs/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/MSSA/CMakeLists.txt b/svf/include/MSSA/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/MSSA/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/MTA/CMakeLists.txt b/svf/include/MTA/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/MTA/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/MemoryModel/CMakeLists.txt b/svf/include/MemoryModel/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/MemoryModel/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/SABER/CMakeLists.txt b/svf/include/SABER/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/SABER/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/SVFIR/CMakeLists.txt b/svf/include/SVFIR/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/SVFIR/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/Util/CMakeLists.txt b/svf/include/Util/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/Util/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/include/WPA/CMakeLists.txt b/svf/include/WPA/CMakeLists.txt deleted file mode 100644 index 94acc7861..000000000 --- a/svf/include/WPA/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Collect all .h (and .hpp) files and add them to the headers fileset of the SvfCore package -file(GLOB_RECURSE _LOCAL_HEADERS *.h *.hpp) -message(STATUS "Found local headers in ${CMAKE_CURRENT_LIST_DIR}: ${_LOCAL_HEADERS}") - -# Add the headers to the sources of libSvfCore; note the base directory -# in the fileset points to the /svf/include directory -target_sources( - SvfCore - PUBLIC FILE_SET - HEADERS - BASE_DIRS - ${SVF_CORE_INCLUDES} - FILES - ${_LOCAL_HEADERS}) diff --git a/svf/lib/AE/CMakeLists.txt b/svf/lib/AE/CMakeLists.txt deleted file mode 100644 index 00fe4bacd..000000000 --- a/svf/lib/AE/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(Core) -add_subdirectory(Svfexe) diff --git a/svf/lib/AE/Core/CMakeLists.txt b/svf/lib/AE/Core/CMakeLists.txt deleted file mode 100644 index 3499e5aea..000000000 --- a/svf/lib/AE/Core/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_AE_CORE_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_AE_CORE_SOURCES}) diff --git a/svf/lib/AE/Svfexe/CMakeLists.txt b/svf/lib/AE/Svfexe/CMakeLists.txt deleted file mode 100644 index 109ebffab..000000000 --- a/svf/lib/AE/Svfexe/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_AE_SVFEXE_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_AE_SVFEXE_SOURCES}) diff --git a/svf/lib/CFL/CMakeLists.txt b/svf/lib/CFL/CMakeLists.txt deleted file mode 100644 index 691f8c775..000000000 --- a/svf/lib/CFL/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_CFL_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_CFL_SOURCES}) diff --git a/svf/lib/CMakeLists.txt b/svf/lib/CMakeLists.txt deleted file mode 100644 index 5a321dd6b..000000000 --- a/svf/lib/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_subdirectory(AE) -add_subdirectory(CFL) -add_subdirectory(DDA) -add_subdirectory(FastCluster) -add_subdirectory(Graphs) -add_subdirectory(MemoryModel) -add_subdirectory(MSSA) -add_subdirectory(MTA) -add_subdirectory(SABER) -add_subdirectory(SVFIR) -add_subdirectory(Util) -add_subdirectory(WPA) diff --git a/svf/lib/DDA/CMakeLists.txt b/svf/lib/DDA/CMakeLists.txt deleted file mode 100644 index 8fc30d870..000000000 --- a/svf/lib/DDA/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_DDA_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_DDA_SOURCES}) diff --git a/svf/lib/FastCluster/CMakeLists.txt b/svf/lib/FastCluster/CMakeLists.txt deleted file mode 100644 index c864c4465..000000000 --- a/svf/lib/FastCluster/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_FASTCLUSTER_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_FASTCLUSTER_SOURCES}) diff --git a/svf/lib/Graphs/CMakeLists.txt b/svf/lib/Graphs/CMakeLists.txt deleted file mode 100644 index c97b578fb..000000000 --- a/svf/lib/Graphs/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_GRAPHS_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_GRAPHS_SOURCES}) diff --git a/svf/lib/MSSA/CMakeLists.txt b/svf/lib/MSSA/CMakeLists.txt deleted file mode 100644 index 311f0a049..000000000 --- a/svf/lib/MSSA/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_MSSA_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_MSSA_SOURCES}) diff --git a/svf/lib/MTA/CMakeLists.txt b/svf/lib/MTA/CMakeLists.txt deleted file mode 100644 index e426a8ad3..000000000 --- a/svf/lib/MTA/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_MTA_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_MTA_SOURCES}) diff --git a/svf/lib/MemoryModel/CMakeLists.txt b/svf/lib/MemoryModel/CMakeLists.txt deleted file mode 100644 index d54cfd6c7..000000000 --- a/svf/lib/MemoryModel/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_MEMORYMODEL_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_MEMORYMODEL_SOURCES}) diff --git a/svf/lib/SABER/CMakeLists.txt b/svf/lib/SABER/CMakeLists.txt deleted file mode 100644 index 39d60dbab..000000000 --- a/svf/lib/SABER/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_SABER_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_SABER_SOURCES}) diff --git a/svf/lib/SVFIR/CMakeLists.txt b/svf/lib/SVFIR/CMakeLists.txt deleted file mode 100644 index 91bf0e89c..000000000 --- a/svf/lib/SVFIR/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_SVFIR_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_SVFIR_SOURCES}) diff --git a/svf/lib/Util/CMakeLists.txt b/svf/lib/Util/CMakeLists.txt deleted file mode 100644 index 16b8e9abd..000000000 --- a/svf/lib/Util/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_UTIL_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_UTIL_SOURCES}) diff --git a/svf/lib/Util/ExtAPI.cpp b/svf/lib/Util/ExtAPI.cpp index 301f98bf4..07cdb87a5 100644 --- a/svf/lib/Util/ExtAPI.cpp +++ b/svf/lib/Util/ExtAPI.cpp @@ -135,14 +135,16 @@ std::string ExtAPI::getExtBcPath() return extBcPath; // 3. Get location generated by CMakeLists.txt from `config.h` header file (if SVF was installed) - if (setExtBcPath(SVF_EXTAPI_FILE)) // Full path is available (for custom file names) + if (setExtBcPath(SVF_INSTALL_EXTAPI_BC)) return extBcPath; - if (setExtBcPath(SVF_EXTAPI_DIR "/extapi.bc")) // Based on directory & default filename + if (setExtBcPath(SVF_BUILD_EXTAPI_BC)) return extBcPath; // 4. Get location in build tree based from `config.h` header file (if SVF was only built) if (setExtBcPath(SVF_BUILD_DIR "/lib/extapi.bc")) return extBcPath; + if (setExtBcPath(SVF_BUILD_DIR "/include/extapi.bc")) + return extBcPath; // 5. Get location based on environment variable $ENV{SVF_DIR} if (setExtBcPath(getFilePath("SVF_DIR"))) @@ -156,8 +158,8 @@ std::string ExtAPI::getExtBcPath() << "To override the default locations for \"extapi.bc\", you can:" << std::endl << "\t1. Use the command line argument \"-extapi=path/to/extapi.bc\"" << std::endl << "\t2. Use the \"setExtBcPath()\" function *BEFORE* calling \"buildSVFModule()\"" << std::endl - << "\t3. Override the paths in \"svf/Util/config.h\" (WARNING: will be overwritten when " - << "rebuilding SVF (generated by CMakeLists.txt))" << std::endl; + << "\t3. Override the paths in \"include/SVF/Util/config.h\" (WARNING: will be overwritten " + << "when rebuilding SVF (generated by CMakeLists.txt))" << std::endl; abort(); } diff --git a/svf/lib/WPA/CMakeLists.txt b/svf/lib/WPA/CMakeLists.txt deleted file mode 100644 index 2bdad20a0..000000000 --- a/svf/lib/WPA/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Grab all .cpp source files in this directory and add them to the SvfCore package -file(GLOB_RECURSE SVF_CORE_WPA_SOURCES *.cpp) -target_sources(SvfCore PRIVATE ${SVF_CORE_WPA_SOURCES})