Skip to content

Commit

Permalink
Add TBB to build system
Browse files Browse the repository at this point in the history
Requires TBB to be installed on the system for parallel execution, otherwise serial execution
  • Loading branch information
GwGibson committed Aug 11, 2023
1 parent eda691b commit b04df28
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \
python3 python3-pip

# User-settable versions:
# This Dockerfile should support gcc-[7, 8, 9, 10, 11] and clang-[10, 11, 12, 13, 14]
# This Dockerfile should support gcc-[7, 8, 9, 10, 11] and clang-[10, 11, 12, 13, 14, 15]
# Earlier versions of clang will require significant modifications to the IWYU section
ARG GCC_VER="11"
# Add gcc-${GCC_VER}
Expand All @@ -27,7 +27,7 @@ RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
RUN update-alternatives --install /usr/bin/gcc gcc $(which gcc-${GCC_VER}) 100
RUN update-alternatives --install /usr/bin/g++ g++ $(which g++-${GCC_VER}) 100

ARG LLVM_VER="14"
ARG LLVM_VER="15"
# Add clang-${LLVM_VER}
ARG LLVM_URL="http://apt.llvm.org/${VARIANT}/"
ARG LLVM_PKG="llvm-toolchain-${VARIANT}-${LLVM_VER}"
Expand Down Expand Up @@ -60,7 +60,7 @@ RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y --no-install-recommends \
neovim

# Install optional dependencies
# Install dependencies
RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y --no-install-recommends \
doxygen graphviz ccache cppcheck libtbb-dev
Expand Down
17 changes: 8 additions & 9 deletions Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ function(psim_setup_dependencies)
# cpmaddpackage("gh:CLIUtils/[email protected]")
# endif()

if(NOT TARGET TBB::tbb)
cpmaddpackage(
NAME TBB
VERSION 2021.10.0
URL https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.10.0.tar.gz
OPTIONS
"TBB_TEST OFF"
)
endif()
#if(NOT TARGET TBB::tbb)
# cpmaddpackage(
# NAME TBB
# VERSION 2021.10.0
# URL https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.10.0.tar.gz
# OPTIONS
# "TBB_TEST OFF")
#endif()

endfunction()
7 changes: 0 additions & 7 deletions ProjectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ macro(psim_setup_options)
option(psim_ENABLE_CPPCHECK "Enable cpp-check analysis" ON)
option(psim_ENABLE_PCH "Enable precompiled headers" OFF)
option(psim_ENABLE_CACHE "Enable ccache" ON)
option(psim_STATIC_LINK_LIBC "Statically link standard libraries" OFF)
else()
option(psim_ENABLE_IPO "Enable IPO/LTO" ON)
option(psim_WARNINGS_AS_ERRORS "Treat Warnings As Errors" OFF)
Expand All @@ -58,7 +57,6 @@ macro(psim_setup_options)
option(psim_ENABLE_CPPCHECK "Enable cpp-check analysis" OFF)
option(psim_ENABLE_PCH "Enable precompiled headers" OFF)
option(psim_ENABLE_CACHE "Enable ccache" OFF)
option(psim_STATIC_LINK_LIBC "Statically link standard libraries" OFF)
endif()

mark_as_advanced(FORCE ENABLE_DEVELOPER_MODE)
Expand Down Expand Up @@ -99,11 +97,6 @@ endmacro()
macro(psim_local_options)
if(PROJECT_IS_TOP_LEVEL)
include(cmake/StandardProjectSettings.cmake)
# Statically link the standard libraries to allow the executable to run
# on servers with older software
if (psim_STATIC_LINK_LIBC)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
endif()
endif()

add_library(psim_warnings INTERFACE)
Expand Down
4 changes: 0 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ debug:
cmake -S ./ -B ./build -G "Ninja Multi-Config" -DENABLE_DEVELOPER_MODE:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Debug
cmake --build ./build --config Debug

link_libc:
cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE:STRING=Release -Dpsim_STATIC_LINK_LIBC=ON
cmake --build ./build --config Release

format:
ifeq ($(OS), Windows_NT)
pwsh -c '$$files=(git ls-files --exclude-standard); foreach ($$file in $$files) { if ((get-item $$file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $$file } }'
Expand Down
22 changes: 15 additions & 7 deletions psim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ file(GLOB_RECURSE PSIM_SOURCES
set(module_name "psim")
add_library(${module_name} STATIC ${PSIM_SOURCES})

find_package(TBB QUIET)

if(TBB_FOUND)
target_link_libraries(${module_name} PRIVATE TBB::tbb)
else()
message(WARNING "TBB not found. Building without TBB support.")
endif()

target_link_libraries(
${module_name}
PUBLIC psim_options psim_warnings
PUBLIC ${module_name}_options ${module_name}_warnings
)

target_include_directories(psim PUBLIC
target_include_directories(${module_name} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
target_include_directories(psim INTERFACE "${CMAKE_BINARY_DIR}/configured_files/include")
target_include_directories(${module_name} INTERFACE "${CMAKE_BINARY_DIR}/configured_files/include")

# Precompiled Headers
#target_precompile_headers(${module_name} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/psimPch.h")

add_executable(psim.out "./src/main.cpp")
add_executable(${module_name}.out "./src/main.cpp")
target_link_libraries(
psim.out
PUBLIC psim
PRIVATE psim_options psim_warnings TBB::tbb
${module_name}.out
PUBLIC ${module_name}
PRIVATE ${module_name}_options ${module_name}_warnings TBB::tbb
)

0 comments on commit b04df28

Please sign in to comment.