CMakeLists.txt 2.23 KB
Newer Older
1 2 3 4 5 6
# PROJECT: fcontext
cmake_minimum_required(VERSION 3.0)
project(fcontext C)

if (NOT CMAKE_MODULE_PATH)
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
7
endif ()
8 9 10

if (MSVC)
    enable_language(CXX ASM_MASM)
11
else ()
12
    enable_language(CXX ASM)
13
endif ()
14

15 16 17 18
if (MSVC)
    add_definitions(-D_ITERATOR_DEBUG_LEVEL=0)
    add_definitions(-D_HAS_EXCEPTIONS=0)
endif ()
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
add_definitions(-DBOOST_CONTEXT_EXPORT=)

set(HEADER "include/fcontext/fcontext.h")
set(SOURCES "source/stack.c")

# OS
if (APPLE)
    set(CPU_ARCH "combined")
    set(ASM_EXT "all_macho_gas.S")
elseif (ANDROID)
    # Android
    if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
        set(CPU_ARCH "arm")
        set(ASM_EXT "aapcs_elf_gas.S")
    elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
        set(CPU_ARCH "arm64")
        set(ASM_EXT "aapcs_elf_gas.S")
    elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686")
        set(CPU_ARCH "i386")
        set(ASM_EXT "sysv_elf_gas.S")
    elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
        set(CPU_ARCH "x86_64")
        set(ASM_EXT "sysv_elf_gas.S")
42
    endif ()
43 44
elseif (UNIX)
    # PC (x86/x64)
45 46 47 48
    if (CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
        set(CPU_ARCH "arm")
        set(ASM_EXT "aapcs_elf_gas.S") # Untested, but should work for linux/unix
    elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
49
        set(CPU_ARCH "x86_64")
50 51
        set(ASM_EXT "sysv_elf_gas.S")  # Linux/Unix
    else ()
52
        set(CPU_ARCH "i386")
53 54
        set(ASM_EXT "sysv_elf_gas.S")  # Linux/Unix
    endif ()
55 56 57 58
elseif (WIN32)
    # Windows PC
    if (CMAKE_SIZEOF_VOID_P EQUAL 8)
        set(CPU_ARCH "x86_64")
59
    else ()
60
        set(CPU_ARCH "i386")
61
    endif ()
62
    set(ASM_EXT "ms_pe_masm.asm")
63
endif ()
64 65

set(ASM_SOURCES "asm/make_${CPU_ARCH}_${ASM_EXT}"
66 67
        "asm/jump_${CPU_ARCH}_${ASM_EXT}"
        "asm/ontop_${CPU_ARCH}_${ASM_EXT}")
68 69 70

add_library(fcontext STATIC ${SOURCES} ${ASM_SOURCES})
target_include_directories(fcontext
71 72
        PRIVATE include/fcontext
        INTERFACE include)
73

74
set_property(TARGET fcontext PROPERTY INTERPROCEDURAL_OPTIMIZATION FALSE)
75 76 77 78 79
set_target_properties(fcontext PROPERTIES FOLDER Deps ${IOS_GENERAL_PROPERTIES})

install(TARGETS fcontext DESTINATION lib)
install(FILES ${HEADER} DESTINATION include/fcontext)