Codebase list cppad / b83b26b
Simplify by changing extension used for c++ wrapper files. use_swig.cmake: modified UseSWIG.cmake so uses .cpp (not .cxx) for wrappers. Brad Bell 7 years ago
8 changed file(s) with 358 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
6969 #
7070 # macro that acts for cmake like assert acts for C
7171 INCLUDE(cmake/assert.cmake)
72 #
73 # version of UseSWIG.cmake modified so wrapper has .cpp extension
74 INCLUDE(cmake/use_swig.cmake)
7275 # =============================================================================
7376 # command line arguments
7477 # =============================================================================
2929 sed -e 's/^.*: *//' -e 's/ -> /\n/' | \
3030 sed -e '/makefile.in$/d' \
3131 -e '/\/check_copyright.sh$/d' \
32 -e '/\/empty.cpp$/d' \
32 -e '/\/use_swig.cmake$/d' \
3333 -e '/AUTHORS/d' \
3434 -e '/COPYING/d' |
3535 sort -u`
0 ## This file is a modified version of the following file:
1 ## (see old and new text for the modifications).
2 ## repository: https://github.com/Kitware/CMake.git
3 ## version: 2b301e11e2402690c43a7535656cba487559bd1f
4 ## file: Modules/UseSWIG.cmake from
5 ## old text: set(SWIG_CXX_EXTENSION "cxx")
6 ## new text: set(SWIG_CXX_EXTENSION "cpp")
7 ##
8
9 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
10 # file Copyright.txt or https://cmake.org/licensing for details.
11
12 #.rst:
13 # UseSWIG
14 # -------
15 #
16 # Defines the following macros for use with SWIG:
17 #
18 # ::
19 #
20 # SWIG_ADD_LIBRARY(<name>
21 # [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>]
22 # LANGUAGE <language>
23 # SOURCES <file>...
24 # )
25 # - Define swig module with given name and specified language
26 # SWIG_LINK_LIBRARIES(name [ libraries ])
27 # - Link libraries to swig module
28 #
29 # Source files properties on module files can be set before the invocation
30 # of the SWIG_ADD_LIBRARY macro to specify special behavior of SWIG.
31 #
32 # The source file property CPLUSPLUS calls SWIG in c++ mode, e.g.::
33 #
34 # set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON)
35 # swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
36 #
37 # The source file property SWIG_FLAGS adds custom flags to the SWIG executable.
38 #
39 # The source-file property SWIG_MODULE_NAME have to be provided to specify the actual
40 # import name of the module in the target language if it cannot be scanned automatically
41 # from source or different from the module file basename.::
42 #
43 # set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname)
44 #
45 # To get the name of the swig module target library, use: ${SWIG_MODULE_${name}_REAL_NAME}.
46 #
47 # Also some variables can be set to specify special behavior of SWIG.
48 #
49 # CMAKE_SWIG_FLAGS can be used to add special flags to all swig calls.
50 #
51 # CMAKE_SWIG_OUTDIR allows one to specify where to write
52 # the language specific files (swig -outdir option).
53 #
54 # SWIG_OUTFILE_DIR allows one to specify where to write the output file
55 # (swig -o option). If not specified, CMAKE_SWIG_OUTDIR is used.
56 #
57 # The name-specific variable SWIG_MODULE_<name>_EXTRA_DEPS may be used to specify extra
58 # dependencies for the generated modules.
59 #
60 # If the source file generated by swig need some special flag you can use::
61 #
62 # set_source_files_properties( ${swig_generated_file_fullname}
63 # PROPERTIES COMPILE_FLAGS "-bla")
64
65 set(SWIG_CXX_EXTENSION "cpp")
66 set(SWIG_EXTRA_LIBRARIES "")
67
68 set(SWIG_PYTHON_EXTRA_FILE_EXTENSIONS ".py")
69 set(SWIG_JAVA_EXTRA_FILE_EXTENSIONS ".java" "JNI.java")
70
71 #
72 # For given swig module initialize variables associated with it
73 #
74 macro(SWIG_MODULE_INITIALIZE name language)
75 string(TOUPPER "${language}" swig_uppercase_language)
76 string(TOLOWER "${language}" swig_lowercase_language)
77 set(SWIG_MODULE_${name}_LANGUAGE "${swig_uppercase_language}")
78 set(SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${swig_lowercase_language}")
79
80 set(SWIG_MODULE_${name}_REAL_NAME "${name}")
81 if (";${CMAKE_SWIG_FLAGS};" MATCHES ";-noproxy;")
82 set (SWIG_MODULE_${name}_NOPROXY TRUE)
83 endif ()
84 if("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xUNKNOWN")
85 message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found")
86 elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xPYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY)
87 # swig will produce a module.py containing an 'import _modulename' statement,
88 # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32),
89 # unless the -noproxy flag is used
90 set(SWIG_MODULE_${name}_REAL_NAME "_${name}")
91 elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xPERL")
92 set(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
93 elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xCSHARP")
94 # This makes sure that the name used in the generated DllImport
95 # matches the library name created by CMake
96 set(SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport;${name}")
97 endif()
98 endmacro()
99
100 #
101 # For a given language, input file, and output file, determine extra files that
102 # will be generated. This is internal swig macro.
103 #
104
105 macro(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
106 set(${outfiles} "")
107 get_source_file_property(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename
108 ${infile} SWIG_MODULE_NAME)
109 if(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename STREQUAL "NOTFOUND")
110
111 # try to get module name from "%module foo" syntax
112 if ( EXISTS ${infile} )
113 file ( STRINGS ${infile} _MODULE_NAME REGEX "[ ]*%module[ ]*[a-zA-Z0-9_]+.*" )
114 endif ()
115 if ( _MODULE_NAME )
116 string ( REGEX REPLACE "[ ]*%module[ ]*([a-zA-Z0-9_]+).*" "\\1" _MODULE_NAME "${_MODULE_NAME}" )
117 set(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${_MODULE_NAME}")
118
119 else ()
120 # try to get module name from "%module (options=...) foo" syntax
121 if ( EXISTS ${infile} )
122 file ( STRINGS ${infile} _MODULE_NAME REGEX "[ ]*%module[ ]*\\(.*\\)[ ]*[a-zA-Z0-9_]+.*" )
123 endif ()
124 if ( _MODULE_NAME )
125 string ( REGEX REPLACE "[ ]*%module[ ]*\\(.*\\)[ ]*([a-zA-Z0-9_]+).*" "\\1" _MODULE_NAME "${_MODULE_NAME}" )
126 set(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${_MODULE_NAME}")
127
128 else ()
129 # fallback to file basename
130 get_filename_component(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename ${infile} NAME_WE)
131 endif ()
132 endif ()
133
134 endif()
135 foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSIONS})
136 set(${outfiles} ${${outfiles}}
137 "${generatedpath}/${SWIG_GET_EXTRA_OUTPUT_FILES_module_basename}${it}")
138 endforeach()
139 endmacro()
140
141 #
142 # Take swig (*.i) file and add proper custom commands for it
143 #
144 macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
145 set(swig_full_infile ${infile})
146 get_filename_component(swig_source_file_name_we "${infile}" NAME_WE)
147 get_source_file_property(swig_source_file_generated ${infile} GENERATED)
148 get_source_file_property(swig_source_file_cplusplus ${infile} CPLUSPLUS)
149 get_source_file_property(swig_source_file_flags ${infile} SWIG_FLAGS)
150 if("${swig_source_file_flags}" STREQUAL "NOTFOUND")
151 set(swig_source_file_flags "")
152 endif()
153 get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE)
154
155 # If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir
156 if(CMAKE_SWIG_OUTDIR)
157 set(swig_outdir ${CMAKE_SWIG_OUTDIR})
158 else()
159 set(swig_outdir ${CMAKE_CURRENT_BINARY_DIR})
160 endif()
161
162 if(SWIG_OUTFILE_DIR)
163 set(swig_outfile_dir ${SWIG_OUTFILE_DIR})
164 else()
165 set(swig_outfile_dir ${swig_outdir})
166 endif()
167
168 if (NOT SWIG_MODULE_${name}_NOPROXY)
169 SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE}
170 swig_extra_generated_files
171 "${swig_outdir}"
172 "${swig_source_file_fullname}")
173 endif()
174 set(swig_generated_file_fullname
175 "${swig_outfile_dir}/${swig_source_file_name_we}")
176 # add the language into the name of the file (i.e. TCL_wrap)
177 # this allows for the same .i file to be wrapped into different languages
178 string(APPEND swig_generated_file_fullname
179 "${SWIG_MODULE_${name}_LANGUAGE}_wrap")
180
181 if(swig_source_file_cplusplus)
182 string(APPEND swig_generated_file_fullname
183 ".${SWIG_CXX_EXTENSION}")
184 else()
185 string(APPEND swig_generated_file_fullname
186 ".c")
187 endif()
188
189 #message("Full path to source file: ${swig_source_file_fullname}")
190 #message("Full path to the output file: ${swig_generated_file_fullname}")
191 get_directory_property(cmake_include_directories INCLUDE_DIRECTORIES)
192 list(REMOVE_DUPLICATES cmake_include_directories)
193 set(swig_include_dirs)
194 foreach(it ${cmake_include_directories})
195 set(swig_include_dirs ${swig_include_dirs} "-I${it}")
196 endforeach()
197
198 set(swig_special_flags)
199 # default is c, so add c++ flag if it is c++
200 if(swig_source_file_cplusplus)
201 set(swig_special_flags ${swig_special_flags} "-c++")
202 endif()
203 set(swig_extra_flags)
204 if(SWIG_MODULE_${name}_EXTRA_FLAGS)
205 set(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS})
206 endif()
207 add_custom_command(
208 OUTPUT "${swig_generated_file_fullname}" ${swig_extra_generated_files}
209 # Let's create the ${swig_outdir} at execution time, in case dir contains $(OutDir)
210 COMMAND ${CMAKE_COMMAND} -E make_directory ${swig_outdir}
211 COMMAND "${SWIG_EXECUTABLE}"
212 ARGS "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
213 ${swig_source_file_flags}
214 ${CMAKE_SWIG_FLAGS}
215 -outdir ${swig_outdir}
216 ${swig_special_flags}
217 ${swig_extra_flags}
218 ${swig_include_dirs}
219 -o "${swig_generated_file_fullname}"
220 "${swig_source_file_fullname}"
221 MAIN_DEPENDENCY "${swig_source_file_fullname}"
222 DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS}
223 COMMENT "Swig source")
224 set_source_files_properties("${swig_generated_file_fullname}" ${swig_extra_generated_files}
225 PROPERTIES GENERATED 1)
226 set(${outfiles} "${swig_generated_file_fullname}" ${swig_extra_generated_files})
227 endmacro()
228
229 #
230 # Create Swig module
231 #
232 macro(SWIG_ADD_MODULE name language)
233 message(DEPRECATION "SWIG_ADD_MODULE is deprecated. Use SWIG_ADD_LIBRARY instead.")
234 swig_add_library(${name}
235 LANGUAGE ${language}
236 TYPE MODULE
237 SOURCES ${ARGN})
238 endmacro()
239
240
241 macro(SWIG_ADD_LIBRARY name)
242
243 include(CMakeParseArguments)
244 set(options "")
245 set(oneValueArgs LANGUAGE
246 TYPE)
247 set(multiValueArgs SOURCES)
248 cmake_parse_arguments(_SAM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
249
250 if(NOT DEFINED _SAM_LANGUAGE)
251 message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing LANGUAGE argument")
252 endif()
253
254 if(NOT DEFINED _SAM_SOURCES)
255 message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing SOURCES argument")
256 endif()
257
258 if(NOT DEFINED _SAM_TYPE)
259 set(_SAM_TYPE MODULE)
260 elseif("${_SAM_TYPE}" STREQUAL "USE_BUILD_SHARED_LIBS")
261 unset(_SAM_TYPE)
262 endif()
263
264 swig_module_initialize(${name} ${_SAM_LANGUAGE})
265
266 set(swig_dot_i_sources)
267 set(swig_other_sources)
268 foreach(it ${_SAM_SOURCES})
269 if(${it} MATCHES "\\.i$")
270 set(swig_dot_i_sources ${swig_dot_i_sources} "${it}")
271 else()
272 set(swig_other_sources ${swig_other_sources} "${it}")
273 endif()
274 endforeach()
275
276 set(swig_generated_sources)
277 foreach(it ${swig_dot_i_sources})
278 SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source ${it})
279 set(swig_generated_sources ${swig_generated_sources} "${swig_generated_source}")
280 endforeach()
281 get_directory_property(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
282 set_directory_properties(PROPERTIES
283 ADDITIONAL_MAKE_CLEAN_FILES "${swig_extra_clean_files};${swig_generated_sources}")
284 add_library(${SWIG_MODULE_${name}_REAL_NAME}
285 ${_SAM_TYPE}
286 ${swig_generated_sources}
287 ${swig_other_sources})
288 if("${_SAM_TYPE}" STREQUAL "MODULE")
289 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES NO_SONAME ON)
290 endif()
291 string(TOLOWER "${_SAM_LANGUAGE}" swig_lowercase_language)
292 if ("${swig_lowercase_language}" STREQUAL "octave")
293 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
294 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".oct")
295 elseif ("${swig_lowercase_language}" STREQUAL "go")
296 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
297 elseif ("${swig_lowercase_language}" STREQUAL "java")
298 if (APPLE)
299 # In java you want:
300 # System.loadLibrary("LIBRARY");
301 # then JNI will look for a library whose name is platform dependent, namely
302 # MacOS : libLIBRARY.jnilib
303 # Windows: LIBRARY.dll
304 # Linux : libLIBRARY.so
305 set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".jnilib")
306 endif ()
307 elseif ("${swig_lowercase_language}" STREQUAL "lua")
308 if("${_SAM_TYPE}" STREQUAL "MODULE")
309 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
310 endif()
311 elseif ("${swig_lowercase_language}" STREQUAL "python")
312 # this is only needed for the python case where a _modulename.so is generated
313 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
314 # Python extension modules on Windows must have the extension ".pyd"
315 # instead of ".dll" as of Python 2.5. Older python versions do support
316 # this suffix.
317 # http://docs.python.org/whatsnew/ports.html#SECTION0001510000000000000000
318 # <quote>
319 # Windows: .dll is no longer supported as a filename extension for extension modules.
320 # .pyd is now the only filename extension that will be searched for.
321 # </quote>
322 if(WIN32 AND NOT CYGWIN)
323 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".pyd")
324 endif()
325 elseif ("${swig_lowercase_language}" STREQUAL "r")
326 set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
327 elseif ("${swig_lowercase_language}" STREQUAL "ruby")
328 # In ruby you want:
329 # require 'LIBRARY'
330 # then ruby will look for a library whose name is platform dependent, namely
331 # MacOS : LIBRARY.bundle
332 # Windows: LIBRARY.dll
333 # Linux : LIBRARY.so
334 set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
335 if (APPLE)
336 set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".bundle")
337 endif ()
338 endif ()
339 endmacro()
340
341 #
342 # Like TARGET_LINK_LIBRARIES but for swig modules
343 #
344 macro(SWIG_LINK_LIBRARIES name)
345 if(SWIG_MODULE_${name}_REAL_NAME)
346 target_link_libraries(${SWIG_MODULE_${name}_REAL_NAME} ${ARGN})
347 else()
348 message(SEND_ERROR "Cannot find Swig library \"${name}\".")
349 endif()
350 endmacro()
351
2020 # check if we have swig
2121 FIND_PACKAGE(SWIG)
2222 IF( SWIG_FOUND )
23
24 # include the swig specific macros
25 INCLUDE( ${CMAKE_ROOT}/Modules/UseSWIG.cmake )
2623
2724 # swig_control_file: used by the subdirectories below
2825 SET(swig_control_file "${CMAKE_CURRENT_SOURCE_DIR}/cppad_swig.i" )
6161 INCLUDE_DIRECTORIES(${octave_include_dirs})
6262
6363 # SWIG_ADD_MODULE(name language [ files ])
64 SWIG_ADD_MODULE(cppad_swig octave ${swig_control_file} empty.cpp )
64 SWIG_ADD_MODULE(cppad_swig octave ${swig_control_file} )
6565
6666 # SWIG_LINK_LIBRARIES(name [ libraries ])
6767 SWIG_LINK_LIBRARIES(cppad_swig
+0
-1
swig/octave/empty.cpp less more
0 // This file is only used to inform cmake that it is linking C++
3939 INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
4040
4141 # SWIG_ADD_MODULE(name language [ files ])
42 SWIG_ADD_MODULE(cppad_swig python ${swig_control_file} empty.cpp)
42 SWIG_ADD_MODULE(cppad_swig python ${swig_control_file} )
4343
4444 MESSAGE(STATUS "swig_generated_sources=${swig_generated_sources}")
4545
+0
-1
swig/python/empty.cpp less more
0 // This file is only used to inform cmake that it is linking C++