-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
139 lines (113 loc) · 3.54 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# ---
# Copyright (c) 2016 Johan Sköld
# License: https://opensource.org/licenses/ISC
# ---
cmake_minimum_required(VERSION 3.2)
project(sc)
enable_language(C CXX)
enable_testing()
#
# Compiler options
#
if(MSVC)
enable_language(ASM_MASM)
else()
enable_language(ASM)
endif()
# For OSX, CMake already handles passing the appropriate `-arch` parameters
# for C/C++, but we need to do it ourselves for assembly files. Due to this
# bug however we must apply it globally through `CMAKE_ASM_FLAGS`:
# https://cmake.org/Bug/view.php?id=15826
if(CMAKE_OSX_ARCHITECTURES)
string(REPLACE ";" " -arch " SC_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${SC_OSX_ARCHITECTURES}")
endif()
if(CMAKE_OSX_SYSROOT)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT}")
endif()
#
# sc
#
add_library(sc STATIC
include/sc.h
src/context.c
src/sc.c
src/sc_p.h
src/tls.c)
if(MSVC)
target_sources(sc PRIVATE
src/asm/jump_masm.asm
src/asm/make_masm.asm)
if(CMAKE_CL_64 EQUAL 0)
set_source_files_properties(src/asm/jump_masm.asm src/asm/make_masm.asm src/asm/state_masm.asm PROPERTIES
COMPILE_FLAGS "/safeseh /DSC_WIN32")
else()
set_source_files_properties(src/asm/jump_masm.asm src/asm/make_masm.asm src/asm/state_masm.asm PROPERTIES
COMPILE_FLAGS "/DSC_WIN64")
endif()
else()
target_sources(sc PRIVATE
src/asm/jump_gas.S
src/asm/make_gas.S)
endif()
target_compile_options(sc
PRIVATE
$<$<C_COMPILER_ID:GNU>:-Wall -Werror>
$<$<C_COMPILER_ID:Clang>:-Wall -Werror>
$<$<C_COMPILER_ID:AppleClang>:-Wall -Werror>
$<$<C_COMPILER_ID:MSVC>:/W3 /WX>)
target_include_directories(sc
PUBLIC include)
#
# sc_tests
#
add_executable(sc_tests
tests/framework.hpp
tests/main.cpp
tests/sc_tests.cpp
tests/win_tests.cpp)
add_test(NAME sc_tests COMMAND sc_tests)
if(MSVC)
if(CMAKE_CL_64 EQUAL 1)
target_sources(sc_tests PRIVATE
tests/asm/get_rsp_proc_x86_64_ms_pe_masm.asm
tests/asm/get_xmm_register_x86_64_ms_pe_masm.asm
tests/asm/set_xmm_register_x86_64_ms_pe_masm.asm)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT SC_FORCE_32BIT)
target_sources(sc_tests PRIVATE
tests/asm/get_rsp_proc_x86_64_ms_pe_gas.s
tests/asm/get_xmm_register_x86_64_ms_pe_gas.s
tests/asm/set_xmm_register_x86_64_ms_pe_gas.s)
endif()
endif()
if(IOS)
set_target_properties(sc_tests PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_GUI_IDENTIFIER "cc.skold.sc_tests"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ios-info.plist.in"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "cc.skold.sc_tests")
endif()
target_compile_options(sc_tests
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror -std=c++0x>
$<$<CXX_COMPILER_ID:Clang>:-Wall -Werror -std=c++0x>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Werror -std=c++0x>
$<$<CXX_COMPILER_ID:MSVC>:/W3 /WX>)
target_include_directories(sc_tests
PRIVATE
"3rdparty/Catch/include")
target_link_libraries(sc_tests
sc)
#
# Common properties
#
set_target_properties(sc sc_tests PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(SC_FORCE_32BIT)
set_target_properties(sc sc_tests PROPERTIES
COMPILE_FLAGS "-m32"
LINK_FLAGS "-m32")
endif()