Hide the use of FetchContent behind a flag

FetchContent is now disabled by default, when the project is included as
an subproject by another top-level project.
Also, every usage of FetchContent is behind a separate flag to enable and
disable the usage with granular control.
This commit is contained in:
2024-11-18 17:22:03 +01:00
parent ca9ef16d0d
commit c3eb5e6a62
9 changed files with 100 additions and 63 deletions

View File

@@ -47,9 +47,14 @@ if(POLICY CMP0135)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(FetchContent)
include(enable_extensions)
if (PROJECT_IS_TOP_LEVEL)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
if(DRAMSYS_ENABLE_COVERAGE)
include(coverage)
endif()
@@ -57,9 +62,18 @@ endif()
### Project settings ###
option(DRAMSYS_BUILD_TESTS "Build DRAMSys unit tests" OFF)
option(DRAMSYS_BUILD_BENCHMARKS "Build DRAMSys benchmarks" OFF)
option(DRAMSYS_BUILD_CLI "Build DRAMSys Command Line Tool" ON)
option(DRAMSYS_BUILD_CLI "Build DRAMSys Command Line Tool" ${PROJECT_IS_TOP_LEVEL})
option(DRAMSYS_BUILD_TRACE_ANALYZER "Build DRAMSys Trace Analyzer" OFF)
option(DRAMSYS_WITH_DRAMPOWER "Build with DRAMPower support enabled." ON)
option(DRAMSYS_WITH_DRAMPOWER "Build with DRAMPower support enabled." OFF)
# Use sane defaults for FetchContent:
# In case we are the top-level project, get everything by default
# In case we are included in another project, the user might want to provide their own system dependencies
option(DRAMSYS_USE_FETCH_CONTENT "Enable the FetchContent module" ${PROJECT_IS_TOP_LEVEL})
option(DRAMSYS_USE_FETCH_CONTENT_INTERNAL "Enable FetchContent to provide internal dependencies" ${DRAMSYS_USE_FETCH_CONTENT})
option(DRAMSYS_USE_FETCH_CONTENT_SYSTEMC "Enable FetchContent to provide SystemC" ${DRAMSYS_USE_FETCH_CONTENT})
option(DRAMSYS_USE_FETCH_CONTENT_SQLITE3 "Enable FetchContent to provide SQLite3" ${DRAMSYS_USE_FETCH_CONTENT})
option(DRAMSYS_USE_FETCH_CONTENT_NLOHMANN_JSON "Enable FetchContent to provide nlohmann_json" ${DRAMSYS_USE_FETCH_CONTENT})
# TODO: Remove as soon as DRAMPower is updated
set(DRAMSYS_SHARED_LIBS OFF)
@@ -68,12 +82,6 @@ if(DEFINED DRAMSYS_SHARED_LIBS)
set(BUILD_SHARED_LIBS ${DRAMSYS_SHARED_LIBS})
endif()
if (PROJECT_IS_TOP_LEVEL)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
### DRAMSys directories ###
set(DRAMSYS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(DRAMSYS_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
@@ -85,42 +93,52 @@ set(DRAMSYS_EXTENSIONS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extensions")
### Library Settings ###
###############################################
### nlohmann_json ###
add_subdirectory(${DRAMSYS_LIBRARY_DIR})
if (DRAMSYS_USE_FETCH_CONTENT)
include(FetchContent)
if (DRAMSYS_USE_FETCH_CONTENT_NLOHMANN_JSON)
FetchContent_Declare(nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
OVERRIDE_FIND_PACKAGE
)
if (NOT TARGET nlohmann_json::nlohmann_json)
FetchContent_Declare(nlohmann_json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
FetchContent_MakeAvailable(nlohmann_json)
endif()
### SystemC ###
if (NOT TARGET SystemC::systemc) # TODO ist das wirklich so korrekt?
set(DISABLE_COPYRIGHT_MESSAGE True)
if (DRAMSYS_USE_FETCH_CONTENT_SQLITE3)
add_subdirectory(${DRAMSYS_LIBRARY_DIR}/sqlite3)
endif()
if (DRAMSYS_USE_FETCH_CONTENT_SYSTEMC)
set(DISABLE_COPYRIGHT_MESSAGE TRUE)
FetchContent_Declare(
systemc
SystemCLanguage
GIT_REPOSITORY https://github.com/accellera-official/systemc.git
GIT_TAG 2.3.4)
GIT_TAG 2.3.4
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(systemc)
FetchContent_MakeAvailable(SystemCLanguage)
# Set include directories to SYSTEM to suppress warnings
set_target_properties(systemc PROPERTIES SYSTEM TRUE)
else()
find_package(systemc NAMES SystemCLanguage)
endif()
### DRAMPower ###
if (DRAMSYS_WITH_DRAMPOWER)
if (DRAMSYS_WITH_DRAMPOWER AND DRAMSYS_USE_FETCH_CONTENT_INTERNAL)
FetchContent_Declare(
DRAMPower
GIT_REPOSITORY https://github.com/tukl-msd/DRAMPower
GIT_TAG 9e64a1b)
GIT_TAG 9e64a1b
)
FetchContent_MakeAvailable(DRAMPower)
set_target_properties(DRAMPower PROPERTIES FOLDER lib)
endif()
endif()
find_package(SystemCLanguage REQUIRED)
find_package(SQLite3 REQUIRED)
find_package(nlohmann_json REQUIRED)
###############################################
### Source Directory ###

View File

@@ -22,8 +22,8 @@
"inherits": "cmake-pedantic",
"cacheVariables": {
"DRAMSYS_BUILD_TESTS": "ON",
"DRAMSYS_WITH_DRAMPOWER": "ON",
"DRAMSYS_BUILD_TRACE_ANALYZER": "ON"
"DRAMSYS_BUILD_TRACE_ANALYZER": "ON",
"DRAMSYS_WITH_DRAMPOWER": "ON"
}
},
{

View File

@@ -1 +0,0 @@
add_subdirectory(sqlite3)

View File

@@ -2,8 +2,12 @@
### sqlite3 ###
########################################
FetchContent_Declare(sqlite3 URL "https://www.sqlite.org/2022/sqlite-amalgamation-3400100.zip")
FetchContent_MakeAvailable(sqlite3)
FetchContent_Declare(SQLite3
URL "https://www.sqlite.org/2022/sqlite-amalgamation-3400100.zip"
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(SQLite3)
add_library(sqlite3)
target_sources(sqlite3 PRIVATE
@@ -14,11 +18,8 @@ target_sources(sqlite3 PRIVATE
target_include_directories(sqlite3 PUBLIC ${sqlite3_SOURCE_DIR})
set_target_properties(sqlite3 PROPERTIES FOLDER lib)
### Compile options ###
# refer to https://www.sqlite.org/compile.html
target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_RTREE SQLITE_OMIT_LOAD_EXTENSION)
# Use the same name as the FindSQLite3 script of CMake uses

View File

@@ -38,29 +38,35 @@
### TraceAnalyzer ###
########################################
# Add Python3 Dependency:
find_package(Python3 COMPONENTS Development Interpreter)
option(DRAMSYS_USE_FETCH_CONTENT_PYBIND "Enable FetchContent to provide pybind11" ${DRAMSYS_USE_FETCH_CONTENT})
if (DRAMSYS_USE_FETCH_CONTENT)
if (DRAMSYS_USE_FETCH_CONTENT_PYBIND)
FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.13.1.zip
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(pybind11)
endif()
endif()
# Add QT Library:
if (APPLE)
set(Qt5_DIR "/opt/homebrew/opt/qt@5/lib/cmake/Qt5")
endif(APPLE)
find_package(Qt5 COMPONENTS Core Gui Widgets Sql REQUIRED)
find_package(Qwt REQUIRED)
find_package(Python3 COMPONENTS Development Interpreter REQUIRED)
find_package(pybind11 REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Add QWT Dependency:
find_package(Qwt REQUIRED)
add_executable(TraceAnalyzer
businessObjects/commentmodel.cpp
businessObjects/configmodels.cpp

View File

@@ -2,12 +2,22 @@ include(GoogleTest)
set(DRAMSYS_TEST_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.12.1)
option(DRAMSYS_USE_FETCH_CONTENT_GTEST "Enable FetchContent to provide gtest" ${DRAMSYS_USE_FETCH_CONTENT})
FetchContent_MakeAvailable(googletest)
if (DRAMSYS_USE_FETCH_CONTENT)
if (DRAMSYS_USE_FETCH_CONTENT_GTEST)
FetchContent_Declare(
GTest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.12.1
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(GTest)
endif()
endif()
find_package(GTest REQUIRED)
add_subdirectory(tests_configuration)
add_subdirectory(tests_dramsys)

View File

@@ -11,6 +11,7 @@ set_target_properties(tests_configuration PROPERTIES FOLDER tests/configuration)
target_link_libraries(tests_configuration PRIVATE
DRAMSys::config
gtest
gtest_main
)

View File

@@ -14,6 +14,7 @@ target_include_directories(tests_dramsys PUBLIC ${PROJECT_SOURCE_DIR})
set_target_properties(tests_dramsys PROPERTIES FOLDER tests)
target_link_libraries(tests_dramsys
DRAMSys::libdramsys
gtest
gtest_main
)

View File

@@ -13,6 +13,7 @@ set_target_properties(tests_simulator PROPERTIES FOLDER tests/simulator)
target_link_libraries(tests_simulator PRIVATE
simulator
gtest
gtest_main
)