-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
181 lines (151 loc) · 6.23 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
project(exeproxy C)
option(WITH_JAVASCRIPT "Build with JavaScript support" ON)
if(WITH_JAVASCRIPT)
add_definitions(-DWITH_JAVASCRIPT)
endif()
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../cmake/")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mconsole -static -municode")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map,${PROJECT_NAME}.map")
if(WIN32)
set(CMAKE_USE_RELATIVE_PATHS true)
set(CMAKE_SUPPRESS_REGENERATION true)
endif()
include(CheckTypeSize)
CHECK_TYPE_SIZE("void*" OSMSCOUT_PTR_SIZE BUILTIN_TYPES_ONLY)
if(OSMSCOUT_PTR_SIZE EQUAL 8)
set(NPACKD_PLATFORM_X64 TRUE)
set(BITS 64)
else()
set(NPACKD_PLATFORM_X64 FALSE)
set(BITS 32)
endif()
add_definitions(-DUNICODE -D_UNICODE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -g -Os" )
include(CheckCXXCompilerFlag)
# compiler warnings
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX OR CMAKE_COMPILER_IS_GNUCC)
set(NPACKD_WARNING_FLAGS "-Wall -Winit-self -Wwrite-strings -Wextra -Wno-long-long -Wno-overloaded-virtual -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unknown-pragmas")
if(EMSCRIPTEN)
set(NPACKD_WARNING_FLAGS "${NPACKD_WARNING_FLAGS} -Wno-warn-absolute-paths")
elseif(NOT APPLE)
set(NPACKD_WARNING_FLAGS "${NPACKD_WARNING_FLAGS} -Wno-unused-but-set-parameter")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NPACKD_WARNING_FLAGS}")
endif()
# Reads the version number from Version.txt
#
# txt: path to the Version.txt
macro(readVersion txt)
file(STRINGS ${txt} READ_BUILD_NUMBER REGEX "version:.+" LIMIT_COUNT 1)
message(STATUS "Read build number ${READ_BUILD_NUMBER}")
string(REGEX MATCHALL "[0-9]+" _versionComponents "${READ_BUILD_NUMBER}")
list(LENGTH _versionComponents _len)
if (${_len} GREATER 0)
list(GET _versionComponents 0 NPACKD_VERSION_MAJOR)
else()
set(NPACKD_VERSION_MAJOR 0)
endif()
if (${_len} GREATER 1)
list(GET _versionComponents 1 NPACKD_VERSION_MINOR)
else()
set(NPACKD_VERSION_MINOR 0)
endif()
if (${_len} GREATER 2)
list(GET _versionComponents 2 NPACKD_VERSION_PATCH)
else()
set(NPACKD_VERSION_PATCH 0)
endif()
if (${_len} GREATER 3)
list(GET _versionComponents 3 NPACKD_VERSION_TWEAK)
else()
set(NPACKD_VERSION_TWEAK 0)
endif()
set(NPACKD_VERSION "${NPACKD_VERSION_MAJOR}.${NPACKD_VERSION_MINOR}.${NPACKD_VERSION_PATCH}.${NPACKD_VERSION_TWEAK}")
message(STATUS "Build npackd v${NPACKD_VERSION}")
endmacro(readVersion)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast /wd4251")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Oi")
if(CMAKE_CL_64)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj")
endif()
if(MSVC_VERSION GREATER 1500 OR MSVC_VERSION EQUAL 1500)
option(NPACKD_BUILD_MSVC_MP "Enable build with multiple processes in Visual Studio" TRUE)
else()
set(NPACKD_BUILD_MSVC_MP FALSE CACHE BOOL "Compiler option /MP requires at least Visual Studio 2008 (VS9) or newer" FORCE)
endif()
if(NPACKD_BUILD_MSVC_MP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DDLL_EXPORT -DUNICODE -D_UNICODE)
endif()
# Vista
add_definitions(-D_WIN32_WINNT=0x0600)
add_definitions(-DWINVER=0x0600)
if(MINGW)
if(NOT NPACKD_PLATFORM_X64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -fno-tree-slp-vectorize -Wno-error=cast-qual -Wno-unused-local-typedefs")
endif()
if((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX OR CMAKE_COMPILER_IS_GNUCC) AND NOT MINGW)
add_definitions( -Wall -pedantic -fPIC )
check_cxx_compiler_flag(-fvisibility=hidden NPACKD_GCC_VISIBILITY)
if(NPACKD_GCC_VISIBILITY)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE NPACKD_GCC_VERSION)
message(STATUS "Detected g++ ${NPACKD_GCC_VERSION}")
message(STATUS "Enabling GCC visibility flags")
set(NPACKD_GCC_VISIBILITY_FLAGS "-fvisibility=hidden")
set(XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES")
string(TOLOWER "${CMAKE_BUILD_TYPE}" NPACKD_BUILD_TYPE)
if(NPACKD_BUILD_TYPE STREQUAL "debug" AND NPACKD_GCC_VERSION VERSION_LESS "4.2")
message(STATUS "Skipping -fvisibility-inlines-hidden due to possible bug in g++ < 4.2")
else()
if(APPLE)
message(STATUS "Skipping -fvisibility-inlines-hidden due to linker issues")
set(XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN[arch=x86_64] "YES")
else()
set(NPACKD_VISIBILITY_FLAGS "${NPACKD_GCC_VISIBILITY_FLAGS} -fvisibility-inlines-hidden")
set(XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN "YES")
endif()
endif()
endif()
if(NPACKD_PLATFORM_X64 AND NOT APPLE)
add_definitions(-fPIC)
endif()
endif()
# prefer static libraries if making import tool
if(BUILD_IMPORT_TOOL_FOR_DISTRIBUTION AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX OR CMAKE_COMPILER_IS_GNUCC))
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
# postfix for debug builds
if(NOT APPLE)
set(CMAKE_DEBUG_POSTFIX "d")
endif ()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(WITH_JAVASCRIPT)
set(EXEPROXY_SOURCES
src/main.c
src/duktape.c
)
set(EXEPROXY_HEADERS
src/duk_config.h
src/duktape.h
)
else()
set(EXEPROXY_SOURCES
src/main.c
)
set(EXEPROXY_HEADERS "")
endif()
set(OUTPUT_FILE_NAME "exeproxy.exe")
add_executable(exeproxy ${EXEPROXY_SOURCES})
set_property(TARGET exeproxy PROPERTY C_STANDARD 11)
target_link_libraries(exeproxy shell32)
target_include_directories(exeproxy PRIVATE "C:/Program Files/JDK_64_bit/include" "C:/Program Files/JDK_64_bit/include/win32")
target_compile_definitions(exeproxy PRIVATE -D NPACKD_VERSION="${NPACKD_VERSION}")
install(TARGETS exeproxy DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES LICENSE.txt DESTINATION ${CMAKE_INSTALL_PREFIX})