Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the latest version of LLVMCMakeTemplate #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMake/HunterPackages.cmake
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 12 additions & 14 deletions CMake/LLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
# target_link_libraries(${PROJECT_NAME} <PRIVATE|PUBLIC|INTERFACE> 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)

Expand All @@ -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)
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)
27 changes: 16 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down