Create separate static libraries for each src/ subdirectory
MODIFY
CMakeLists.txt
CMakeLists.txt
-cmake_minimum_required(VERSION 3.9)
+cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -89,6 +89,9 @@ elseif(${WIN32})
endif()
add_subdirectory(external)
+
+# Fix the name of the ripes library.
+set(RIPES_LIB ripes_lib)
add_subdirectory(src)
option(RIPES_BUILD_TESTS "Build Ripes tests" OFF)
@@ -102,4 +105,4 @@ add_executable(${APP_NAME} ${SYSTEM_FLAGS} ${ICONS_SRC} ${EXAMPLES_SRC} ${LAYOUT
# Link Qt libraries
target_link_libraries(${APP_NAME} Qt5::Core Qt5::Widgets)
# Link Ripes library
-target_link_libraries(${APP_NAME} ripes_lib)
+target_link_libraries(${APP_NAME} ${RIPES_LIB})

MODIFY
src/CMakeLists.txt
src/CMakeLists.txt
-cmake_minimum_required(VERSION 3.9)
-set(CMAKE_CXX_STANDARD 17)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
+function(check_nonempty_string STR)
+ if ("${STR}" STREQUAL "")
+ message(FATAL_ERROR "Empty string")
+ endif()
+endfunction()
-file(GLOB LIB_SOURCES
- *.cpp
- isa/*.cpp
- cachesim/*.cpp
- editor/*.cpp
- syscall/*.cpp
- version/version.cpp
- assembler/*.cpp
- io/*.cpp
- utilities/*.cpp)
-file(GLOB LIB_HEADERS
- *.h
- isa/*.h
- cachesim/*.h
- editor/*.h
- syscall/*.h
- graphics/*.h
- assembler/*.h
- io/*.h
- utilities/*.h)
-file(GLOB LIB_UIS
- *.ui
- cachesim/*.ui
- syscall/*.ui
- io/*.ui
+# Function to create sub-libraries for the Ripes library. A library is
+# built based on the *.h,*.cpp and *.ui within the immediate directory of
+# the CMakeLists.txt file. If LINK_TO_RIPES_LIB is set, the ${RIPES_LIB}
+# will be linked to the newly defined library.
+function(create_ripes_lib NAME)
+ cmake_parse_arguments(OPTIONS
+ "LINK_TO_RIPES_LIB;FIXED_NAME;EXCLUDE_SRC_INC" # options
+ "" # 1-valued keywords
+ "" # multi-valued keywords
+ ${ARGN})
+
+ file(GLOB LIB_SOURCES *.cpp)
+ file(GLOB LIB_HEADERS *.h)
+ file(GLOB LIB_UI *.ui)
+ if(NOT OPTIONS_FIXED_NAME)
+ check_nonempty_string(NAME)
+ set(LIB_NAME ${NAME}_lib)
+ else()
+ check_nonempty_string(OPTIONS_FIXED_NAME)
+ set(LIB_NAME ${NAME})
+ endif()
+
+ add_library(${LIB_NAME} STATIC ${LIB_SOURCES} ${LIB_HEADERS} ${LIB_UIS})
+ target_compile_features(${LIB_NAME} PRIVATE cxx_std_17)
+ target_include_directories (${LIB_NAME} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
)
-set(RIPES_LIB ripes_lib)
-add_library(${RIPES_LIB} ${LIB_SOURCES} ${LIB_HEADERS} ${LIB_UIS})
-target_include_directories (${RIPES_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
-target_compile_features(${RIPES_LIB} PRIVATE cxx_std_17)
+ target_link_libraries(${LIB_NAME} PUBLIC Qt5::Gui)
+ if(NOT OPTIONS_EXCLUDE_SRC_INC)
+ target_include_directories(${LIB_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/src)
+ endif()
-# Link external libraries
-target_link_libraries(${RIPES_LIB} PUBLIC fancytabbar_lib)
-target_link_libraries(${RIPES_LIB} PUBLIC ${VSRTL_GRAPHICS_LIB} Qt5::Charts)
+ if(OPTIONS_LINK_TO_RIPES_LIB)
+ target_link_libraries(${RIPES_LIB} PUBLIC ${LIB_NAME})
+ endif()
+endfunction()
-add_subdirectory(processors)
-# -----------------------------------------------------------------------------
-# Version control file
-# A file gen_versionnumber.h is generated by version.cmake, containing information
-# regarding the current .git revision.
-# This information is embedded into the binary for future reference, ie. for issue
-# reporting.
-add_custom_target(
- version_file ALL
- # Depend on the dummy file (which is not generated by the versioning script)
- # to ensure that the custom command is executed each time the project is built.
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version/dummy.cpp
- )
+# Create the parent library. This will include everything in the current directory.
+create_ripes_lib(${RIPES_LIB} FIXED_NAME EXCLUDE_SRC_INC)
+
+# All of the following subdirectories will create separate libraries and link them into
+# ripes_lib
+add_subdirectory(isa)
+add_subdirectory(cachesim)
+add_subdirectory(editor)
+add_subdirectory(syscall)
+add_subdirectory(assembler)
+add_subdirectory(io)
+add_subdirectory(utilities)
+add_subdirectory(processors)
+add_subdirectory(version)
-add_dependencies(${RIPES_LIB} version_file)
+# Also link Qt and VSRTL libraries.
+target_link_libraries(${RIPES_LIB} PUBLIC
+ fancytabbar_lib
+ ${VSRTL_GRAPHICS_LIB}
+ Qt5::Charts)
-add_custom_command(
- OUTPUT
- # Dummy file not generated by the sript, but may be used as a dependency
- ${CMAKE_CURRENT_BINARY_DIR}/version/dummy.cpp
- COMMAND
- ${CMAKE_COMMAND}
- -DRIPES_SRC_DIR=${CMAKE_SOURCE_DIR}
- -P ${CMAKE_CURRENT_SOURCE_DIR}/version/version.cmake)
-# Do not run AUTOMOC and AUTOUIC on the generated file (CMake warning)
-# -----------------------------------------------------------------------------

ADD
src/assembler/CMakeLists.txt
+create_ripes_lib(assembler LINK_TO_RIPES_LIB)

MODIFY
src/assembler/rvrelocations.h
src/assembler/rvrelocations.h
#pragma once
+#include "VSRTL/interface/vsrtl_binutils.h"
#include "relocation.h"
-#include "vsrtl_binutils.h"
namespace Ripes {
namespace Assembler {

ADD
src/cachesim/CMakeLists.txt
+create_ripes_lib(cachesim LINK_TO_RIPES_LIB)

MODIFY
src/ccmanager.cpp
src/ccmanager.cpp
#include <QProcess>
#include <QProgressDialog>
+#include <QTextDocument>
namespace Ripes {

MODIFY
src/ccmanager.h
src/ccmanager.h
#include <QObject>
#include <QProcess>
#include <QString>
-#include <QTextDocument>
+
+QT_FORWARD_DECLARE_CLASS(QTextDocument)
+
+#include <memory>
namespace Ripes {

MODIFY
src/console.h
src/console.h
#pragma once
+#include <QTextBlock>
+
#include <QFont>
#include <QPlainTextEdit>

ADD
src/editor/CMakeLists.txt
+create_ripes_lib(editor LINK_TO_RIPES_LIB)

ADD
src/io/CMakeLists.txt
+create_ripes_lib(io LINK_TO_RIPES_LIB)

ADD
src/isa/CMakeLists.txt
+create_ripes_lib(isa LINK_TO_RIPES_LIB)

MODIFY
src/processorhandler.h
src/processorhandler.h
#include <QObject>
#include <memory>
+#include "VSRTL/graphics/gallantsignalwrapper.h"
#include "assembler/assembler.h"
#include "assembler/program.h"
-#include "gallantsignalwrapper.h"
#include "processorregistry.h"
#include "processors/interface/ripesprocessor.h"
#include "syscall/ripes_syscall.h"
-#include "vsrtl_widget.h"
+#include "VSRTL/graphics/vsrtl_widget.h"
namespace Ripes {

ADD
src/syscall/CMakeLists.txt
+create_ripes_lib(syscall LINK_TO_RIPES_LIB)

ADD
src/utilities/CMakeLists.txt
+create_ripes_lib(utilities LINK_TO_RIPES_LIB)

ADD
src/version/CMakeLists.txt
+create_ripes_lib(version LINK_TO_RIPES_LIB)
+
+# -----------------------------------------------------------------------------
+# Version control file
+# A file gen_versionnumber.h is generated by version.cmake, containing information
+# regarding the current .git revision.
+# This information is embedded into the binary for future reference, ie. for issue
+# reporting.
+add_custom_target(
+ version_file ALL
+ # Depend on the dummy file (which is not generated by the versioning script)
+ # to ensure that the custom command is executed each time the project is built.
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
+ )
+
+add_dependencies(version_lib version_file)
+
+add_custom_command(
+ OUTPUT
+ # Dummy file not generated by the sript, but may be used as a dependency
+ ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
+ COMMAND
+ ${CMAKE_COMMAND}
+ -DRIPES_SRC_DIR=${CMAKE_SOURCE_DIR}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)

Create separate static libraries for each src/ subdirectory (#143)