cmake_minimum_required(VERSION 3.10)
project(predictable_parallel_patterns
        VERSION 0.0.1
        DESCRIPTION "predictable parallel patterns for scalable smart systems using work stealing"
        LANGUAGES CXX ASM)

set(CMAKE_CXX_STANDARD 17)

# seperate library and test/example executable output paths.
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

# specific setup code is located in individual files.
include(cmake/DisabelInSource.cmake)
include(cmake/SetupOptimizationLevel.cmake)
include(cmake/SetupAssemblyOutput.cmake)
include(cmake/SetupThreadingSupport.cmake)
include(cmake/SetupThreadSanitizer.cmake)
include(cmake/SetupAddressSanitizer.cmake)
include(cmake/SetupEasyProfiler.cmake)
include(cmake/SetupDebugSymbols.cmake)

# make our internal cmake script collection avaliable in the build process.
list(APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/cmake")

# Include external libraries within the project structure (prefered, as no instalation is reqired).
# Each library has an own CMakeLists.txt that should make it avaliabale as a library target,
# thus allowing one to include it as any cmake dependency later on.
add_subdirectory(extern/catch2)
add_subdirectory(extern/picosha2)
add_subdirectory(extern/benchmark_base)
add_subdirectory(extern/benchmark_runner)

# Include all internal subprojects (library, examples, testing).
add_subdirectory(lib/context_switcher)
add_subdirectory(lib/pls)

# ...add a custom target that will only build the library when installing.
# This can allow us to speed up the installation on embedded devices.
ADD_CUSTOM_TARGET(install.pls
        ${CMAKE_COMMAND}
        -DBUILD_TYPE=${CMAKE_BUILD_TYPE}
        -P ${CMAKE_BINARY_DIR}/cmake_install.cmake)
ADD_DEPENDENCIES(install.pls context_switcher pls)

# Include examples
add_subdirectory(app/playground)
add_subdirectory(app/benchmark_fft)
add_subdirectory(app/benchmark_unbalanced)
add_subdirectory(app/benchmark_matrix)
add_subdirectory(app/benchmark_fib)
add_subdirectory(app/context_switch)

# Add optional tests
option(PACKAGE_TESTS "Build the tests" ON)
if (PACKAGE_TESTS)
    enable_testing()
    add_subdirectory(test)
    add_test(NAME AllTests COMMAND tests)
endif ()
