forked from yuangu/sxtwl_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
191 lines (138 loc) · 5.78 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
182
183
184
185
186
187
188
189
190
191
cmake_minimum_required(VERSION 3.6)
project(sxtwl_cpp)
IF(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
ENDIF()
#编译库的例子
add_subdirectory(src)
#编译例子
if(SXTWL_BUILD_EXAMPLES)
add_subdirectory(example)
endif(SXTWL_BUILD_EXAMPLES)
#python的接口导出
# if(SXTWL_WRAPPER_PYTHON)
# find_package(SWIG REQUIRED)
# include(${SWIG_USE_FILE})
# find_package(PythonLibs)
# include_directories(${PYTHON_INCLUDE_DIR} "./src")
# set(CMAKE_SWIG_FLAGS)
# set_property(SOURCE swig/sxtwl.i PROPERTY CPLUSPLUS ON)
# SWIG_ADD_MODULE(sxtwl_python python swig/sxtwl.i)
# #SWIG_ADD_LIBRARY(sxtwl_python MODULE LANGUAGE python SOURCES swig/sxtwl.i)
# SWIG_LINK_LIBRARIES(sxtwl_python ${PYTHON_LIBRARY} sxtwl)
# endif(SXTWL_WRAPPER_PYTHON)
#java的接口导出(适作于android, 在externalNativeBuild 下的cmake加上 arguments "-DSXTWL_WRAPPER_JAVA=1")
if(SXTWL_WRAPPER_JAVA)
# find_package(SWIG REQUIRED)
IF(ANDROID)
message(STATUS "Android Jni")
ELSE(ANDROID)
find_package(JNI)
if(${JNI_FOUND})
message(STATUS "Jni Found")
else(${JNI_FOUND})
message(FATAL_ERROR "not found Jni")
endif()
endif(ANDROID)
include_directories(${JNI_INCLUDE_DIRS} "./src")
# #增加包名
# IF(ANDROID)
# #参考:https://github.com/sureshjoshi/android-ndk-swig-example/blob/master/AS3/app/CMakeLists.txt
# set(JAVA_GEN_PACKAGE "com.seantone.sxtwl")
# string(REPLACE "." "/" JAVA_GEN_SUBDIR ${JAVA_GEN_PACKAGE})
# set(JAVA_GEN_DIR ${Project_SOURCE_DIR}/src/main/java/${JAVA_GEN_SUBDIR})
# # -s选项为strip,不strip生成的库文件会很大
# set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
# set(CMAKE_SWIG_FLAGS -c++ -package ${JAVA_GEN_PACKAGE})
# if(CONSOLE)
# else(CONSOLE)
# set(CMAKE_SWIG_OUTDIR ${JAVA_GEN_DIR})
# set(SWIG_OUTFILE_DIR ${Project_SOURCE_DIR}/src/main/sxtwl_jni_cpp/sxtwlJAVA_wrap.cxx)
# endif(CONSOLE)
# ELSE(ANDROID)
# set(CMAKE_SWIG_FLAGS -c++ -package com.huoyaojing.sxtwl)
# ENDIF(ANDROID)
# set_property(SOURCE swig/sxtwl.i PROPERTY CPLUSPLUS ON)
# SWIG_ADD_MODULE(sxtwl_java java com.seantone.sxtwl)
# #SWIG_ADD_LIBRARY(sxtwl_java MODULE LANGUAGE java SOURCES swig/sxtwl.i)
# SWIG_LINK_LIBRARIES(sxtwl_java ${JNI_LIBRARIES} sxtwl)
add_library(sxtwl_java SHARED "./export/java/sxtwl_wrap.cxx")
target_link_libraries(sxtwl_java sxtwl ${JNI_LIBRARIES})
endif(SXTWL_WRAPPER_JAVA)
#lua接口的导出
if(SXTWL_WRAPPER_LUA)
# find_package(SWIG REQUIRED)
# include(${SWIG_USE_FILE})
find_package(Lua)
if(${LUA_FOUND})
message(STATUS "lua Found")
else(${LUA_FOUND})
message(FATAL_ERROR "not found lua")
endif()
include_directories(${LUA_INCLUDE_DIR} "./src")
add_library(sxtwl_lua SHARED "./export/lua/sxtwl_wrap.cxx")
target_link_libraries(sxtwl_lua sxtwl ${LUA_LIBRARIES})
# set_property(SOURCE swig/sxtwl.i PROPERTY CPLUSPLUS ON)
# set(CMAKE_SWIG_FLAGS)
# SWIG_ADD_MODULE(sxtwl_lua lua swig/sxtwl.i)
# #SWIG_ADD_LIBRARY(sxtwl_lua MODULE LANGUAGE lua SOURCES swig/sxtwl.i)
# SWIG_LINK_LIBRARIES(sxtwl_lua ${LUA_LIBRARIES} sxtwl)
endif(SXTWL_WRAPPER_LUA)
#C#接口导出
if(SXTWL_WRAPPER_CSHARP)
# find_package(SWIG REQUIRED)
# include(${SWIG_USE_FILE})
include_directories( "./src")
add_library(sxtwl_csharp SHARED "./export/C#/sxtwl_wrap.cxx")
target_link_libraries(sxtwl_csharp sxtwl)
# set_property(SOURCE swig/sxtwl.i PROPERTY CPLUSPLUS ON)
# set(CMAKE_SWIG_FLAGS)
# SWIG_ADD_MODULE(sxtwl_csharp csharp swig/sxtwl.i)
# #SWIG_ADD_LIBRARY(sxtwl_csharp MODULE LANGUAGE csharp SOURCES swig/sxtwl.i)
# SWIG_LINK_LIBRARIES(sxtwl_csharp sxtwl)
endif(SXTWL_WRAPPER_CSHARP)
#php接口导出(仅支持php5和php7)
if(SXTWL_WRAPPER_PHP5)
include(${CMAKE_SOURCE_DIR}/cmake/FindPHP.cmake)
include_directories(${PHP_INCLUDE_DIRS} ${PHP_EXTENSIONS_INCLUDE_DIR} "./src")
add_library(sxtwl_php5 SHARED "./export/php5/sxtwl_wrap.cxx")
target_link_libraries(sxtwl_php5 sxtwl)
# find_package(SWIG REQUIRED)
# include(${SWIG_USE_FILE})
# set_property(SOURCE swig/sxtwl.i PROPERTY CPLUSPLUS ON)
# set(CMAKE_SWIG_FLAGS)
# if(${PHP_VERSION_MAJOR} MATCHES 7)
# SWIG_ADD_MODULE(sxtwl_php php7 swig/sxtwl.i)
# else(${PHP_VERSION_MAJOR} MATCHES 7)
# SWIG_ADD_MODULE(sxtwl_php php swig/sxtwl.i)
# endif(${PHP_VERSION_MAJOR} MATCHES 7)
# SWIG_LINK_LIBRARIES(sxtwl_php sxtwl )
endif(SXTWL_WRAPPER_PHP5)
if(SXTWL_WRAPPER_PHP7)
include(${CMAKE_SOURCE_DIR}/cmake/FindPHP.cmake)
include_directories(${PHP_INCLUDE_DIRS} ${PHP_EXTENSIONS_INCLUDE_DIR} "./src")
add_library(sxtwl_php7 SHARED "./export/php5/sxtwl_wrap.cxx")
target_link_libraries(sxtwl_php7 sxtwl)
# find_package(SWIG REQUIRED)
# include(${SWIG_USE_FILE})
# set_property(SOURCE swig/sxtwl.i PROPERTY CPLUSPLUS ON)
# set(CMAKE_SWIG_FLAGS)
# if(${PHP_VERSION_MAJOR} MATCHES 7)
# SWIG_ADD_MODULE(sxtwl_php php7 swig/sxtwl.i)
# else(${PHP_VERSION_MAJOR} MATCHES 7)
# SWIG_ADD_MODULE(sxtwl_php php swig/sxtwl.i)
# endif(${PHP_VERSION_MAJOR} MATCHES 7)
# SWIG_LINK_LIBRARIES(sxtwl_php sxtwl )
endif(SXTWL_WRAPPER_PHP7)
# for golang
if(SXTWL_WRAPPER_GO)
include_directories("./src")
add_library(sxtwl_go STATIC "./export/golang/sxtwl_wrap.cxx")
target_link_libraries(sxtwl_go sxtwl)
endif(SXTWL_WRAPPER_GO)
# for c
if(SXTWL_WRAPPER_C)
add_subdirectory(c)
endif(SXTWL_WRAPPER_C)