CMakeLists.txt 2.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
cmake_minimum_required(VERSION 3.10)
project(context_switcher
        VERSION 0.0.1
        DESCRIPTION "allows to execute functions and lambdas on a new stack and switch between them"
        LANGUAGES CXX ASM)

set(CMAKE_CXX_STANDARD 11)

# Platform Support - Edit this when porting the context switch facility.
# We are rather conservative with our flags, maybe more systems follow implemented calling conventions.
# See our documentation and boost context for help when adding a new system.
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
    SET(CONTEXT_SWITCH_ASSEMBLY "asm/enter_context_x86_64.s" "asm/switch_context_x86_64.s")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
    SET(CONTEXT_SWITCH_ASSEMBLY "asm/enter_context_arm32.s" "asm/switch_context_arm32.s")
else ()
    MESSAGE(FATAL_ERROR "Platform (${CMAKE_SYSTEM_PROCESSOR} on ${CMAKE_SYSTEM_NAME}) not supported! Please see Readme for instructions to port.")
endif ()
message("-- Context Switcher: ${CMAKE_SYSTEM_PROCESSOR} running ${CMAKE_SYSTEM_NAME}")

add_library(context_switcher STATIC
        ${CONTEXT_SWITCH_ASSEMBLY}
23 24 25 26
        include/context_switcher/context_switcher.h src/context_switcher.cpp
        include/context_switcher/assembly_bindings.h
        include/context_switcher/continuation.h
        include/context_switcher/lambda_capture.h)
27 28 29 30 31 32 33 34 35 36

# Add everything in `./include` to be in the include path of this project
target_include_directories(context_switcher
        PUBLIC
        $<INSTALL_INTERFACE:include>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/src
        )

37 38 39 40 41 42 43 44 45 46 47 48 49
# Installation on the system (we pack the context switcher with pls for now...)
INSTALL(TARGETS context_switcher
        EXPORT pls-targets
        LIBRARY DESTINATION lib/context_switcher
        ARCHIVE DESTINATION lib/context_switcher
        )
# ...all headers in `include`
INSTALL(
        DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/pls
        DESTINATION include
        FILES_MATCHING PATTERN "*.h*"
)