ENH: Initial import of swig. Start working towards Bug #749 - Add swig support module to cmake

This commit is contained in:
Andy Cedilnik 2004-04-30 12:11:02 -04:00
parent 858564fb10
commit 257daa4635
6 changed files with 405 additions and 0 deletions

75
Modules/FindPHP4.cmake Normal file
View File

@ -0,0 +1,75 @@
#
# This module finds if PHP4 is installed and determines where the include files
# and libraries are. It also determines what the name of the library is. This
# code sets the following variables:
#
# PHP4_INCLUDE_PATH = path to where object.h can be found
# PHP4_EXECUTABLE = full path to the php4 binary
#
SET(PHP4_POSSIBLE_INCLUDE_PATHS
/usr/include/php4
/usr/local/include/php4
/usr/include/php
/usr/local/include/php
/usr/local/apache/php
)
SET(PHP4_POSSIBLE_LIB_PATHS
/usr/lib
)
FIND_PATH(PHP4_FOUND_INCLUDE_PATH main/php.h
${PHP4_POSSIBLE_INCLUDE_PATHS})
IF(PHP4_FOUND_INCLUDE_PATH)
SET(php4_paths "${PHP4_POSSIBLE_INCLUDE_PATHS}")
FOREACH(php4_path Zend main TSRM)
SET(php4_paths ${php4_paths} "${PHP4_FOUND_INCLUDE_PATH}/${php4_path}")
ENDFOREACH(php4_path Zend main TSRM)
SET(PHP4_INCLUDE_PATH "${php4_paths}" INTERNAL "PHP4 include paths")
ENDIF(PHP4_FOUND_INCLUDE_PATH)
FIND_PROGRAM(PHP4_EXECUTABLE
NAMES php4 php
PATHS
/usr/bin
/usr/local/bin
)
MARK_AS_ADVANCED(
PHP4_EXECUTABLE
PHP4_FOUND_INCLUDE_PATH
)
IF(APPLE)
# this is a hack for now
SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
"${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -Wl,-flat_namespace")
FOREACH(symbol
__efree
__emalloc
__estrdup
__object_init_ex
__zend_get_parameters_array_ex
__zend_list_find
__zval_copy_ctor
_add_property_zval_ex
_alloc_globals
_compiler_globals
_convert_to_double
_convert_to_long
_zend_error
_zend_hash_find
_zend_register_internal_class_ex
_zend_register_list_destructors_ex
_zend_register_resource
_zend_rsrc_list_get_rsrc_type
_zend_wrong_param_count
_zval_used_for_init
)
SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
"${CMAKE_SHARED_MODULE_CREATE_C_FLAGS},-U,${symbol}")
ENDFOREACH(symbol)
ENDIF(APPLE)

View File

@ -0,0 +1,64 @@
#
# This module finds if PERL is installed and determines where the include files
# and libraries are. It also determines what the name of the library is. This
# code sets the following variables:
#
# PERL_INCLUDE_PATH = path to where object.h can be found
# PERL_EXECUTABLE = full path to the perl binary
#
SET(PERL_POSSIBLE_INCLUDE_PATHS
/usr/lib/perl/5.8.3/CORE
/usr/lib/perl/5.8.2/CORE
/usr/lib/perl/5.8.1/CORE
/usr/lib/perl/5.8.0/CORE
/usr/lib/perl/5.8/CORE
)
SET(PERL_POSSIBLE_LIB_PATHS
/usr/lib
)
FIND_PATH(PERL_INCLUDE_PATH perl.h
${PERL_POSSIBLE_INCLUDE_PATHS})
FIND_PROGRAM(PERL_EXECUTABLE
NAMES perl
PATHS
/usr/bin
/usr/local/bin
)
IF(PERL_EXECUTABLE)
EXEC_PROGRAM(${PERL_EXECUTABLE}
ARGS -e "'use Config; print $Config{libperl}, \"\\n\"'"
OUTPUT_VARIABLE PERL_LIBRARY_OUTPUT_VARIABLE
RETURN_VALUE PERL_LIBRARY_RETURN_VALUE
)
IF(NOT PERL_LIBRARY_RETURN_VALUE)
FOREACH(path ${PERL_POSSIBLE_LIB_PATHS})
SET(PERL_POSSIBLE_LIBRARY_NAME ${PERL_POSSIBLE_LIBRARY_NAME} "${path}/${PERL_LIBRARY_OUTPUT_VARIABLE}")
ENDFOREACH(path ${PERL_POSSIBLE_LIB_PATHS})
ENDIF(NOT PERL_LIBRARY_RETURN_VALUE)
EXEC_PROGRAM(${PERL_EXECUTABLE}
ARGS -e "'use Config; print $Config{cppflags}, \"\\n\"'"
OUTPUT_VARIABLE PERL_CPPFLAGS_OUTPUT_VARIABLE
RETURN_VALUE PERL_CPPFLAGS_RETURN_VALUE
)
IF(NOT PERL_CPPFLAGS_RETURN_VALUE)
SET(PERL_EXTRA_C_FLAGS ${PERL_CPPFLAGS_OUTPUT_VARIABLE})
SEPARATE_ARGUMENTS(PERL_EXTRA_C_FLAGS)
ENDIF(NOT PERL_CPPFLAGS_RETURN_VALUE)
ENDIF(PERL_EXECUTABLE)
FIND_LIBRARY(PERL_LIBRARY
NAMES ${PERL_POSSIBLE_LIBRARY_NAME} perl5.8.0
PATHS ${PERL_POSSIBLE_LIB_PATHS}
)
MARK_AS_ADVANCED(
PERL_INCLUDE_PATH
PERL_EXECUTABLE
PERL_LIBRARY
)

27
Modules/FindPike.cmake Normal file
View File

@ -0,0 +1,27 @@
#
# This module finds if PIKE is installed and determines where the include files
# and libraries are. It also determines what the name of the library is. This
# code sets the following variables:
#
# PIKE_INCLUDE_PATH = path to where object.h can be found
# PIKE_EXECUTABLE = full path to the pike binary
#
FILE(GLOB PIKE_POSSIBLE_INCLUDE_PATHS
/usr/include/pike/*
/usr/local/include/pike/*)
FIND_PATH(PIKE_INCLUDE_PATH program.h
${PIKE_POSSIBLE_INCLUDE_PATHS})
FIND_PROGRAM(PIKE_EXECUTABLE
NAMES pike7.4
PATHS
/usr/bin
/usr/local/bin
)
MARK_AS_ADVANCED(
PIKE_EXECUTABLE
PIKE_INCLUDE_PATH
)

37
Modules/FindRuby.cmake Normal file
View File

@ -0,0 +1,37 @@
#
# This module finds if RUBY is installed and determines where the include files
# and libraries are. It also determines what the name of the library is. This
# code sets the following variables:
#
# RUBY_INCLUDE_PATH = path to where object.h can be found
# RUBY_EXECUTABLE = full path to the ruby binary
#
SET(RUBY_POSSIBLE_INCLUDE_PATHS
/usr/lib/ruby/1.8/i386-linux
)
SET(RUBY_POSSIBLE_LIB_PATHS
/usr/lib
)
FIND_PATH(RUBY_INCLUDE_PATH ruby.h
${RUBY_POSSIBLE_INCLUDE_PATHS})
FIND_LIBRARY(RUBY_LIBRARY
NAMES ruby1.8
PATHS ${RUBY_POSSIBLE_LIB_PATHS}
)
FIND_PROGRAM(RUBY_EXECUTABLE
NAMES ruby1.8
PATHS
/usr/bin
/usr/local/bin
)
MARK_AS_ADVANCED(
RUBY_EXECUTABLE
RUBY_LIBRARY
RUBY_INCLUDE_PATH
)

35
Modules/FindSWIG.cmake Normal file
View File

@ -0,0 +1,35 @@
SET(SWIG_FOUND FOOBAR)
FIND_PATH(SWIG_DIR
SWIGConfig.cmake
/usr/share/swig1.3
/usr/local/share/swig1.3)
FIND_PATH(SWIG_DIR
swig.swg
/usr/share/swig1.3
/usr/local/share/swig1.3)
IF(EXISTS ${SWIG_DIR})
IF("x${SWIG_DIR}x" MATCHES "^x${CMAKE_ROOT}/Modulesx$")
MESSAGE("SWIG_DIR should not be modules subdirectory of CMake")
ENDIF("x${SWIG_DIR}x" MATCHES "^x${CMAKE_ROOT}/Modulesx$")
IF(EXISTS ${SWIG_DIR}/SWIGConfig.cmake)
INCLUDE(${SWIG_DIR}/SWIGConfig.cmake)
ELSE(EXISTS ${SWIG_DIR}/SWIGConfig.cmake)
FIND_PROGRAM(SWIG_EXECUTABLE
NAMES swig-1.3 swig
PATHS /usr/bin /usr/local/bin)
SET(SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake)
ENDIF(EXISTS ${SWIG_DIR}/SWIGConfig.cmake)
ENDIF(EXISTS ${SWIG_DIR})
IF("x${SWIG_FOUND}x" MATCHES "^xFOOBARx$")
SET(SWIG_FOUND 0)
IF(SWIG_DIR)
IF(EXISTS ${SWIG_USE_FILE})
IF(EXISTS ${SWIG_EXECUTABLE})
SET(SWIG_FOUND 1)
ENDIF(EXISTS ${SWIG_EXECUTABLE})
ENDIF(EXISTS ${SWIG_USE_FILE})
ENDIF(SWIG_DIR)
ENDIF("x${SWIG_FOUND}x" MATCHES "^xFOOBARx$")

167
Modules/UseSWIG.cmake Normal file
View File

@ -0,0 +1,167 @@
SET(SWIG_CXX_EXTENSION "cxx")
SET(SWIG_EXTRA_LIBRARIES "")
SET(SWIG_PYTHON_EXTRA_FILE_EXTENSION "py")
#
# For given swig module initialize variables associated with it
#
MACRO(SWIG_MODULE_INITIALIZE name language)
STRING(TOUPPER "${language}" swig_uppercase_language)
STRING(TOLOWER "${language}" swig_lowercase_language)
SET(SWIG_MODULE_${name}_LANGUAGE "${swig_uppercase_language}")
SET(SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${swig_lowercase_language}")
IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$")
MESSAGE(FATAL_ERROR "SWIG Error: Language \"${language}\" not found")
ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$")
SET(SWIG_MODULE_${name}_REAL_NAME "${name}")
IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$")
SET(SWIG_MODULE_${name}_REAL_NAME "_${name}")
ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$")
IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$")
SET(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$")
ENDMACRO(SWIG_MODULE_INITIALIZE)
#
# For a given language, input file, and output file, determine extra files that
# will be generated
#
MACRO(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
FOREACH(it ${SWIG_PYTHON_EXTRA_FILE_EXTENSION})
SET(outfiles ${outfiles}
"${generatedpath}/${infile}.${it}")
ENDFOREACH(it)
ENDMACRO(SWIG_GET_EXTRA_OUTPUT_FILES)
#
# Take swig (*.i) file and add proper custom commands for it
#
MACRO(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
SET(swig_full_infile ${infile})
GET_FILENAME_COMPONENT(swig_source_file_path "${infile}" PATH)
GET_FILENAME_COMPONENT(swig_source_file_name_we "${infile}" NAME_WE)
GET_SOURCE_FILE_PROPERTY(swig_source_file_generated ${infile} GENERATED)
GET_SOURCE_FILE_PROPERTY(swig_source_file_cplusplus ${infile} CPLUSPLUS)
SET(swig_source_file_fullname "${infile}")
IF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
STRING(REGEX REPLACE
"^${CMAKE_CURRENT_SOURCE_DIR}" ""
swig_source_file_relative_path
"${swig_source_file_path}")
ELSE(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
IF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}")
STRING(REGEX REPLACE
"^${CMAKE_CURRENT_BINARY_DIR}" ""
swig_source_file_relative_path
"${swig_source_file_path}")
SET(swig_source_file_generated 1)
ELSE(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}")
SET(swig_source_file_relative_path "${swig_source_file_path}")
IF(swig_source_file_generated)
SET(swig_source_file_fullname "${CMAKE_CURRENT_BINARY_DIR}/${infile}")
ELSE(swig_source_file_generated)
SET(swig_source_file_fullname "${CMAKE_CURRENT_SOURCE_DIR}/${infile}")
ENDIF(swig_source_file_generated)
ENDIF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_BINARY_DIR}")
ENDIF(${swig_source_file_path} MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
SET(swig_generated_file_fullname
"${CMAKE_CURRENT_BINARY_DIR}")
IF(swig_source_file_relative_path)
SET(swig_generated_file_fullname
"${swig_generated_file_fullname}/${swig_source_file_relative_path}")
ENDIF(swig_source_file_relative_path)
SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE}
swig_extra_generated_files
"${swig_generated_file_fullname}"
"${swig_source_file_name_we}")
SET(swig_generated_file_fullname
"${swig_generated_file_fullname}/${swig_source_file_name_we}")
SET(swig_generated_file_fullname
"${swig_generated_file_fullname}_wrap")
IF(swig_source_file_cplusplus)
SET(swig_generated_file_fullname
"${swig_generated_file_fullname}.${SWIG_CXX_EXTENSION}")
ELSE(swig_source_file_cplusplus)
SET(swig_generated_file_fullname
"${swig_generated_file_fullname}.c")
ENDIF(swig_source_file_cplusplus)
#MESSAGE("Full path to source file: ${swig_source_file_fullname}")
#MESSAGE("Full path to the output file: ${swig_generated_file_fullname}")
GET_DIRECTORY_PROPERTY(cmake_include_directories INCLUDE_DIRECTORIES)
SET(swig_include_dirs)
FOREACH(it ${cmake_include_directories})
SET(swig_include_dirs ${swig_include_dirs} "-I${it}")
ENDFOREACH(it)
SET(swig_special_flags)
IF(swig_source_file_cplusplus)
SET(swig_special_flags ${swig_special_flags} "-c++")
ELSE(swig_source_file_cplusplus)
SET(swig_special_flags ${swig_special_flags} "-c")
ENDIF(swig_source_file_cplusplus)
SET(swig_extra_flags)
IF(SWIG_MODULE_${name}_EXTRA_FLAGS)
SET(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS})
ENDIF(SWIG_MODULE_${name}_EXTRA_FLAGS)
ADD_CUSTOM_COMMAND(
OUTPUT "${swig_generated_file_fullname}"
COMMAND "${SWIG_EXECUTABLE}"
ARGS "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
${swig_special_flags}
${swig_extra_flags}
${swig_include_dirs}
-o "${swig_generated_file_fullname}"
"${swig_source_file_fullname}"
MAIN_DEPENDENCY "${swig_source_file_fullname}"
COMMENT "Swig source")
SET_SOURCE_FILES_PROPERTIES("${swig_generated_file_fullname}"
PROPERTIES GENERATED 1)
SET(${outfiles} "${swig_generated_file_fullname}")
ENDMACRO(SWIG_ADD_SOURCE_TO_MODULE)
#
# Create Swig module
#
MACRO(SWIG_ADD_MODULE name language)
SWIG_MODULE_INITIALIZE(${name} ${language})
SET(swig_dot_i_sources)
SET(swig_other_sources)
FOREACH(it ${ARGN})
IF(${it} MATCHES ".*\\.i$")
SET(swig_dot_i_sources ${swig_dot_i_sources} "${it}")
ELSE(${it} MATCHES ".*\\.i$")
SET(swig_other_sources ${swig_other_sources} "${it}")
ENDIF(${it} MATCHES ".*\\.i$")
ENDFOREACH(it)
SET(swig_generated_sources)
FOREACH(it ${swig_dot_i_sources})
SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source ${it})
SET(swig_generated_sources ${swig_generated_sources} "${swig_generated_source}")
ENDFOREACH(it)
ADD_LIBRARY(${SWIG_MODULE_${name}_REAL_NAME}
MODULE
${swig_generated_sources}
${swig_other_sources})
SET_TARGET_PROPERTIES(${SWIG_MODULE_${name}_REAL_NAME}
PROPERTIES PREFIX "")
ENDMACRO(SWIG_ADD_MODULE)
#
# Like TARGET_LINK_LIBRARIES but for swig modules
#
MACRO(SWIG_LINK_LIBRARIES name)
IF(SWIG_MODULE_${name}_REAL_NAME)
TARGET_LINK_LIBRARIES(${SWIG_MODULE_${name}_REAL_NAME} ${ARGN})
ELSE(SWIG_MODULE_${name}_REAL_NAME)
MESSAGE(SEND_ERROR "Cannot find Swig library \"${name}\".")
ENDIF(SWIG_MODULE_${name}_REAL_NAME)
ENDMACRO(SWIG_LINK_LIBRARIES name)