diff options
-rw-r--r-- | CMakeLists.txt | 21 | ||||
-rw-r--r-- | Makefile | 54 | ||||
-rw-r--r-- | cmake/CMakeLists-sysc-external.txt | 40 | ||||
-rw-r--r-- | cmake/CMakeLists-sysc-fetch.txt | 20 |
4 files changed, 92 insertions, 43 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 36103f8..4d1526f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,9 @@ cmake_minimum_required(VERSION 3.14) project(systemc_playground CXX) -set(src ${CMAKE_CURRENT_SOURCE_DIR}/src) - -set(CMAKE_PREFIX_PATH $ENV{SYSTEMC_HOME}) -find_package(SystemCLanguage CONFIG REQUIRED) - -# Set CXX std based on SystemC configuration. -set(CMAKE_CXX_STANDARD ${SystemC_CXX_STANDARD} CACHE STRING "C++ standard to build all targets.") +# Include SYSTEMC either as source or external project. +#include(cmake/CMakeLists-sysc-fetch.txt) +include(cmake/CMakeLists-sysc-external.txt) set(simulations event @@ -18,11 +14,14 @@ set(simulations lt_bus ) +set(src ${CMAKE_CURRENT_SOURCE_DIR}/src) + foreach(sim IN ITEMS ${simulations}) - add_executable(${sim} ${src}/${sim}.cc) - target_include_directories(${sim} PRIVATE ${src}) - target_compile_options(${sim} PRIVATE -Wall -Wextra) - target_link_libraries(${sim} SystemC::systemc) + set(target pg-${sim}) + add_executable(${target} ${src}/${sim}.cc) + target_compile_options(${target} PRIVATE -Wall -Wextra) + target_include_directories(${target} PRIVATE ${src}) + target_link_libraries(${target} SystemC::systemc) endforeach() # Include tests. @@ -10,12 +10,12 @@ ifeq ($V,1) endif SRCS = $(shell find src test -type f -name \*.h -or -name \*.cc) -BINS = $(SRCS:src/%.cc=BUILD/PLAYGROUND/%) +BINS = $(SRCS:src/%.cc=BUILD/pg-%) # -- SYSTEMC PLAYGROUND -------------------------------------------------------- -build: $(SYSTEMC_HOME)/lib/libsystemc.a BUILD/PLAYGROUND/CMakeCache.txt $(SRCS) - ninja -C BUILD/PLAYGROUND $(NINJA_FLAGS) +build: config + ninja -C BUILD $(NINJA_FLAGS) run: build @for B in $(BINS); do \ @@ -23,48 +23,38 @@ run: build $$B; \ done -run/%: $(SYSTEMC_HOME)/lib/libsystemc.a BUILD/PLAYGROUND/CMakeCache.txt src/%.cc - ninja -C BUILD/PLAYGROUND $(NINJA_FLAGS) $* - BUILD/PLAYGROUND/$* +run/%: config + ninja -C BUILD $(NINJA_FLAGS) pg-$* + BUILD/pg-$* test: build - cd BUILD/PLAYGROUND/test && ctest --output-on-failure $(CCTEST_FLAGS) + cd BUILD/test && ctest --output-on-failure $(CCTEST_FLAGS) -BUILD/PLAYGROUND/CMakeCache.txt: CMakeLists.txt - cmake -B BUILD/PLAYGROUND $@ -S . \ +config: BUILD/CMakeCache.txt cmake/CMakeLists-sysc-external.txt cmake/CMakeLists-sysc-fetch.txt +BUILD/CMakeCache.txt: CMakeLists.txt + # SystemC options: + # BUILD_SHARED_LIBS + cmake -B BUILD -S . \ -G Ninja \ -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ -DCMAKE_BUILD_TYPE=DEBUG \ - #-DCMAKE_FIND_DEBUG_MODE=ON - ln -sfn BUILD/PLAYGROUND/compile_commands.json - #ninja -C $@ -t compdb > compile_commands.json - -# -- SYSTEMC ------------------------------------------------------------------- - -$(SYSTEMC_HOME)/lib/libsystemc.a: BUILD/SYSC/CMakeCache.txt - ninja -C BUILD/SYSC install $(NINJA_FLAGS) - -BUILD/SYSC/CMakeCache.txt: systemc - cmake -B BUILD/SYSC -S systemc \ - -G Ninja \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ - -DCMAKE_BUILD_TYPE=DEBUG \ - -DCMAKE_INSTALL_PREFIX=$(SYSTEMC_HOME) \ + -DCMAKE_CXX_STANDARD=14 \ -DBUILD_SHARED_LIBS=OFF \ - -DCMAKE_CXX_STANDARD=14 - -systemc: - git clone --depth=1 https://github.com/accellera-official/systemc.git + #-DCMAKE_FIND_DEBUG_MODE=ON + ln -sfn BUILD/compile_commands.json # -- UTIL ---------------------------------------------------------------------- +targets: + ninja -C BUILD -t targets + fmt: - clang-format -i $(shell find src test -type f -name \*.h -or -name \*.cc) + clang-format -i $(SRCS) # -- CLEAN --------------------------------------------------------------------- clean: - $(RM) -r BUILD/PLAYGROUND compile_commands.json + ninja -C BUILD clean -distclean: clean - $(RM) -r BUILD $(SYSTEMC_HOME) systemc +distclean: + $(RM) -r BUILD compile_commands.json diff --git a/cmake/CMakeLists-sysc-external.txt b/cmake/CMakeLists-sysc-external.txt new file mode 100644 index 0000000..8346c34 --- /dev/null +++ b/cmake/CMakeLists-sysc-external.txt @@ -0,0 +1,40 @@ +# Integrate SYSTEMC as external project. +# +# External projects are not available during cmake configuration step, but only +# during the build step. Therefore we must maintain some targets manually, +# representing the parts of the external project we want to use (eg library). + +include(ExternalProject) + +set(SYSTEMC_HOME ${CMAKE_BINARY_DIR}/deps/systemc) + +ExternalProject_Add( + systemc_external + GIT_REPOSITORY https://github.com/accellera-official/systemc + GIT_TAG master + GIT_SHALLOW ON + GIT_PROGRESS ON + CMAKE_ARGS + # Fwd cmake outer cmake args. + -DCMAKE_INSTALL_PREFIX=${SYSTEMC_HOME} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + # SystemC specific args. + -DBUILD_SHARED_LIBS=OFF + -DENABLE_ASSERTIONS=ON + INSTALL_BYPRODUCTS + ${CMAKE_BINARY_DIR}/deps/systemc/lib/libsystemc.a +) + +# Define pseudo target (import lib) for usage in cmake. +add_library(SystemC::systemc STATIC IMPORTED GLOBAL) +add_dependencies(SystemC::systemc systemc_external) + +# Create include dir such that we can set include dir property below. +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/deps/systemc/include) + +# Set library properties. +set_target_properties(SystemC::systemc PROPERTIES + IMPORTED_LOCATION ${SYSTEMC_HOME}/lib/libsystemc.a + INTERFACE_INCLUDE_DIRECTORIES ${SYSTEMC_HOME}/include +) diff --git a/cmake/CMakeLists-sysc-fetch.txt b/cmake/CMakeLists-sysc-fetch.txt new file mode 100644 index 0000000..4afd154 --- /dev/null +++ b/cmake/CMakeLists-sysc-fetch.txt @@ -0,0 +1,20 @@ +# Integrate SYSTEMC as source project. +# +# FetchContent makes the dependency available during cmake configuration step +# and acts similar to *add_subdirectory*, that means all targets of the +# sub-project are available in the main project. +# +# NOTE: Target name must be unique across the main project and all sub-project, +# names may clash :^) + +include(FetchContent) + +FetchContent_Declare( + systemc + GIT_REPOSITORY https://github.com/accellera-official/systemc + GIT_TAG master + EXCLUDE_FROM_ALL +) + +# This makes all targets from the sub-project available. +FetchContent_MakeAvailable(systemc) |