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

Fix CMake issues for using Ramulator as a dependency in other projects #54

Open
wants to merge 2 commits into
base: main
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
111 changes: 72 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,93 +1,126 @@
cmake_minimum_required(VERSION 3.14)

project(
Ramulator
Ramulator2
VERSION 2.0
LANGUAGES CXX
)

#### Prompt the build type ####
# Configure build type ========================================================

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
message("Configuring ${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_Version}...")

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DRAMULATOR_DEBUG")

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Dramulator2_DEBUG")
# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

# Project settings ============================================================

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
###############################

set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)

#### External libraries ####
# External libraries ==========================================================

include(FetchContent)
set(FETCHCONTENT_UPDATES_DISCONNECTED ON CACHE BOOL "Skip updating the external dependencies after populating them for the first time")

set(FETCHCONTENT_UPDATES_DISCONNECTED ON CACHE BOOL
"Skip update of external dependencies after first build."
)

message("Configuring yaml-cpp...")
option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" OFF)
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" OFF)
option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp as a shared library" OFF)
set(YAML_CPP_BUILD_CONTRIB OFF)
set(YAML_CPP_BUILD_TOOLS OFF)
set(YAML_BUILD_SHARED_LIBS OFF)
FetchContent_Declare(
yaml-cpp
yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG yaml-cpp-0.7.0
SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/yaml-cpp
GIT_TAG yaml-cpp-0.7.0
)
FetchContent_MakeAvailable(yaml-cpp)
include_directories(${yaml-cpp_SOURCE_DIR}/include)
message("Done configuring yaml-cpp.")

message("Configuring spdlog...")
FetchContent_Declare(
spdlog
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.11.0
SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/spdlog
GIT_TAG v1.11.0
)
FetchContent_MakeAvailable(spdlog)
include_directories(${spdlog_SOURCE_DIR}/include)
message("Done configuring spdlog.")

message("Configuring argparse...")
FetchContent_Declare(
argparse
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
GIT_TAG v2.9
SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/argparse
GIT_TAG v3.0
)
FetchContent_MakeAvailable(argparse)
include_directories(${argparse_SOURCE_DIR}/include)
message("Done configuring argparse.")
##################################

include_directories(${CMAKE_SOURCE_DIR}/src)
# Import object targets =======================================================

add_subdirectory(src)

add_library(ramulator SHARED)
set_target_properties(ramulator PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}
# Shared library target =======================================================

add_library(ramulator2 SHARED)
target_include_directories(ramulator2 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(
ramulator
PUBLIC yaml-cpp
PUBLIC spdlog
ramulator2
PRIVATE
spdlog
yaml-cpp
ramulator2_base
ramulator2_test
ramulator2_frontend
ramulator2_translation
ramulator2_memory_system
ramulator2_addr_mapper
ramulator2_dram
ramulator2_controller
)

add_executable(ramulator-exe)
# Executable target ===========================================================

add_executable(ramulator2_main ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)
target_link_libraries(
ramulator-exe
# PRIVATE -Wl,--whole-archive ramulator -Wl,--no-whole-archive
PRIVATE ramulator
PRIVATE argparse
ramulator2_main
PRIVATE
ramulator2
argparse
spdlog
yaml-cpp
)

set_target_properties(
ramulator-exe
PROPERTIES
set_target_properties(ramulator2_main PROPERTIES
OUTPUT_NAME ramulator2
)

add_subdirectory(src)
# Install =====================================================================

install(TARGETS ramulator2
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)

install(TARGETS ramulator2_main
RUNTIME DESTINATION bin
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/
DESTINATION include
FILES_MATCHING PATTERN "*.h"
)
6 changes: 0 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ add_subdirectory(memory_system)
add_subdirectory(addr_mapper)
add_subdirectory(dram)
add_subdirectory(dram_controller)

target_sources(
ramulator-exe
PRIVATE
main.cpp
)
26 changes: 15 additions & 11 deletions src/addr_mapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
add_library(ramulator-addrmapper OBJECT)
add_library(ramulator2_addr_mapper OBJECT)

target_sources(
ramulator-addrmapper PRIVATE
addr_mapper.h

impl/linear_mappers.cpp
impl/rit.cpp
impl/rit.h
target_include_directories(ramulator2_addr_mapper PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/..
)

target_link_libraries(
ramulator
target_sources(ramulator2_addr_mapper
PUBLIC
addr_mapper.h
impl/rit.h

PRIVATE
ramulator-addrmapper
impl/linear_mappers.cpp
impl/rit.cpp
)

target_link_libraries(ramulator2_addr_mapper PRIVATE
spdlog
yaml-cpp
)
51 changes: 31 additions & 20 deletions src/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
add_library(ramulator-base OBJECT)
add_library(ramulator2_base OBJECT)

target_sources(
ramulator-base PRIVATE
base.h
factory.h factory.cpp
type.h
exception.h
logging.h logging.cpp
debug.h
param.h
utils.h utils.cpp
config.h config.cpp
clocked.h
stats.h stats.cpp
request.h request.cpp
serialization.h
target_include_directories(ramulator2_base PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/..
)

target_link_libraries(
ramulator
target_sources(ramulator2_base
PUBLIC
base.h
factory.h
type.h
exception.h
logging.h
debug.h
param.h
utils.h
config.h
clocked.h
stats.h
request.h
serialization.h

PRIVATE
ramulator-base
)
factory.cpp
logging.cpp
utils.cpp
config.cpp
stats.cpp
request.cpp
)

target_link_libraries(ramulator2_base PRIVATE
spdlog
yaml-cpp
)
3 changes: 3 additions & 0 deletions src/base/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Ramulator {

const std::string Logging::default_logger_pattern = "[%n] %^[%l]%$ %v";
bool Logging::base_logger_registered = Logging::_create_base_logger();

Logger_t Logging::create_logger(std::string name, std::string pattern) {
auto logger = spdlog::stdout_color_st("Ramulator::" + name);

Expand Down
16 changes: 8 additions & 8 deletions src/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ using Logger_t = std::shared_ptr<spdlog::logger>;

class Logging {
private:
inline static const std::string default_logger_pattern = "[%n] %^[%l]%$ %v";
static const std::string default_logger_pattern;

public:
/**
* @brief Create an spdlog logger.
*
*
* @param name The name of the logger
* @return Logger_t
* @return Logger_t
*/
static Logger_t create_logger(std::string name, std::string pattern = default_logger_pattern);

/**
* @brief Returns a pointer to the logger by its name.
*
* @param name
* @return Logger_t
*
* @param name
* @return Logger_t
*/
static Logger_t get(std::string name);

private:
static bool _create_base_logger();
inline static bool base_logger_registered = _create_base_logger();
static bool base_logger_registered;

public:
Logging() = delete;
Logging(const Logging&) = delete;
Expand Down
52 changes: 31 additions & 21 deletions src/dram/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
add_library(ramulator-dram OBJECT)
add_library(ramulator2_dram OBJECT)

target_sources(
ramulator-dram PRIVATE
dram.h node.h spec.h lambdas.h

lambdas/preq.h lambdas/rowhit.h lambdas/rowopen.h lambdas/action.h lambdas/power.h

impl/DDR3.cpp
impl/DDR4.cpp
impl/DDR4-VRR.cpp
impl/DDR4-RVRR.cpp
impl/DDR5.cpp
impl/DDR5-VRR.cpp
impl/DDR5-RVRR.cpp
impl/LPDDR5.cpp
impl/HBM.cpp
impl/HBM2.cpp
impl/HBM3.cpp
target_include_directories(ramulator2_dram PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/..
)

target_link_libraries(
ramulator
target_sources(ramulator2_dram
PUBLIC
dram.h
node.h
spec.h
lambdas.h
lambdas/preq.h
lambdas/rowhit.h
lambdas/rowopen.h
lambdas/action.h
lambdas/power.h

PRIVATE
ramulator-dram
impl/DDR3.cpp
impl/DDR4.cpp
impl/DDR4-VRR.cpp
impl/DDR4-RVRR.cpp
impl/DDR5.cpp
impl/DDR5-VRR.cpp
impl/DDR5-RVRR.cpp
impl/LPDDR5.cpp
impl/HBM.cpp
impl/HBM2.cpp
impl/HBM3.cpp
)

target_link_libraries(ramulator2_dram PRIVATE
spdlog
yaml-cpp
)
Loading