diff --git a/CMake/HunterPackages.cmake b/CMake/HunterPackages.cmake new file mode 100644 index 0000000..9828073 --- /dev/null +++ b/CMake/HunterPackages.cmake @@ -0,0 +1,16 @@ +# Set up Hunter +set(HUNTER_URL "https://github.com/LLVMParty/hunter/archive/51571e846b8dc24997bd43e6459f67babceea77d.zip") +set(HUNTER_SHA1 "53679D956A97DD135723A43C79C363E5312B5490") + +set(HUNTER_LLVM_VERSION 11.0.1) +set(HUNTER_LLVM_CMAKE_ARGS + LLVM_ENABLE_CRASH_OVERRIDES=OFF + LLVM_ENABLE_ASSERTIONS=ON + LLVM_ENABLE_PROJECTS=clang;lld +) +set(HUNTER_PACKAGES LLVM) + +include(FetchContent) +message(STATUS "Fetching hunter...") +FetchContent_Declare(SetupHunter GIT_REPOSITORY https://github.com/cpp-pm/gate) +FetchContent_MakeAvailable(SetupHunter) \ No newline at end of file diff --git a/CMake/LLVM.cmake b/CMake/LLVM.cmake index dc7d8bf..46f895d 100644 --- a/CMake/LLVM.cmake +++ b/CMake/LLVM.cmake @@ -3,24 +3,19 @@ # target_link_libraries(${PROJECT_NAME} LLVM) # The include directories and compile definitions will be properly handled. +set(CMAKE_FOLDER_LLVM "${CMAKE_FOLDER}") +if(CMAKE_FOLDER) + set(CMAKE_FOLDER "${CMAKE_FOLDER}/LLVM") +else() + set(CMAKE_FOLDER "LLVM") +endif() + # Find LLVM find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") -# Find the libraries that correspond to the LLVM components that we wish to use -set(LLVM_LIBRARIES - LLVMCore - LLVMSupport - LLVMPasses - LLVMIRReader - LLVMExecutionEngine - LLVMX86AsmParser - LLVMX86CodeGen - LLVMTarget - LLVMInterpreter) - # Split the definitions properly (https://weliveindetail.github.io/blog/post/2017/07/17/notes-setup.html) separate_arguments(LLVM_DEFINITIONS) @@ -32,5 +27,8 @@ message(STATUS "LLVM tools: ${LLVM_TOOLS_BINARY_DIR}") add_library(LLVM INTERFACE) target_include_directories(LLVM SYSTEM INTERFACE ${LLVM_INCLUDE_DIRS}) -target_link_libraries(LLVM INTERFACE ${LLVM_LIBRARIES}) -target_compile_definitions(LLVM INTERFACE ${LLVM_DEFINITIONS} -DNOMINMAX) \ No newline at end of file +target_link_libraries(LLVM INTERFACE ${LLVM_AVAILABLE_LIBS}) +target_compile_definitions(LLVM INTERFACE ${LLVM_DEFINITIONS} -DNOMINMAX) + +set(CMAKE_FOLDER "${CMAKE_FOLDER_LLVM}") +unset(CMAKE_FOLDER_LLVM) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c32244..63deb03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,26 +2,27 @@ # https://cliutils.gitlab.io/modern-cmake/ cmake_minimum_required(VERSION 3.15) +# Hunter package configuration +include(CMake/HunterPackages.cmake) + project(llvm8) # Enable solution folder support set_property(GLOBAL PROPERTY USE_FOLDERS ON) -# Append the CMake module search path so we can use our own modules -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake) - # Require c++20 set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # LLVM wrapper -include(LLVM) +include(CMake/LLVM.cmake) # MSVC-specific options if(MSVC) - # This assumes the installed LLVM was built in Release mode - set(CMAKE_C_FLAGS_RELWITHDEBINFO "/ZI /Od /Ob0 /DNDEBUG" CACHE STRING "" FORCE) - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/ZI /Od /Ob0 /DNDEBUG" CACHE STRING "" FORCE) + # TODO: This assumes the installed LLVM was built in Release mode + # TODO: this is not very friendly cmake, probably this should respect the cache and not override the user's choice + set(CMAKE_C_FLAGS_DEBUG "/ZI /Od /Ob0 /DNDEBUG" CACHE STRING "" FORCE) + set(CMAKE_CXX_FLAGS_DEBUG "/ZI /Od /Ob0 /DNDEBUG" CACHE STRING "" FORCE) if(${LLVM_USE_CRT_RELEASE} STREQUAL "MD") set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) @@ -32,10 +33,14 @@ if(MSVC) endif() endif() -include_directories(include) - -add_executable(${PROJECT_NAME} src/main.cpp src/instructions.hpp src/utils.hpp src/argparse.hpp) +add_executable(${PROJECT_NAME} + src/main.cpp + src/instructions.hpp + src/utils.hpp + src/argparse.hpp +) target_link_libraries(${PROJECT_NAME} PRIVATE LLVM) +target_include_directories(${PROJECT_NAME} PRIVATE include) -# Set the plugin as the startup project +# Set the main project as the startup project set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) \ No newline at end of file diff --git a/README.md b/README.md index 211d6e4..80f69a9 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Open up the solution in your IDE and build it! The binary is called `llvm8{.exe} ```sh # this assumes that llvm.exe is placed in the project root folder. -llvm.exe --rom ./roms/boot.ch8 --code "0-88" +llvm8.exe --rom ./roms/boot.ch8 --code "0-88" ``` This will write a new file called `boot.ch8.ll`. To recompile this to Windows or macOS use the `make.bat` and `make.sh` scripts respectively: