Skip to content

Commit

Permalink
add lua, csharp, java, octave modular support
Browse files Browse the repository at this point in the history
  • Loading branch information
vigsterkr committed Jul 30, 2013
1 parent ce0e8fb commit 54232cc
Show file tree
Hide file tree
Showing 17 changed files with 596 additions and 18 deletions.
39 changes: 35 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
# COMPFLAGS_SWIG_CPP="-g $COMPFLAGS_SWIG_CPP"
ENDIF()

################# EXAMPLES ##################
OPTION(BUILD_EXAMPLES "Build Examples" ON)

################# DATATYPES #################
LIST(APPEND DEFINES -DUSE_CHAR)
LIST(APPEND DEFINES -DUSE_BOOL)
Expand Down Expand Up @@ -297,7 +300,7 @@ ENDIF()

# JSON
IF (PKG_CONFIG_FOUND)
pkg_search_module(JSON libjson json json-c)
pkg_search_module(JSON libjson>=0.11 json>=0.11 json-c>=0.11)
IF (JSON_FOUND)
SET(HAVE_JSON 1)
LIST(APPEND DEFINES -DHAVE_JSON)
Expand Down Expand Up @@ -377,6 +380,8 @@ SET(CMAKE_SWIG_FLAGS "${CMAKE_SWIG_FLAGS};${DEFINES}")

OPTION(USE_SWIG_DIRECTORS "" OFF)

FIND_PACKAGE(Ruby)

FIND_PACKAGE(SWIG 2.0.4)
IF (SWIG_FOUND)
FIND_PACKAGE(PythonLibs)
Expand All @@ -398,17 +403,39 @@ IF (SWIG_FOUND)
FIND_PACKAGE(Java)
IF (Java_JAVAC_EXECUTABLE)
FIND_PACKAGE(JNI)
FIND_PACKAGE(ApacheAnt)
IF (JNI_FOUND)
SET(JavaModular OFF CACHE BOOL ON)
SET(TARGET_SWIGFLAGS "-package\;org.shogun")
add_subdirectory(src/interfaces/java_modular)
ENDIF()
ENDIF()

FIND_PACKAGE(Ruby)
FIND_PACKAGE(Lua50)
FIND_PACKAGE(Matlab)
IF (RUBY_EXECUTABLE)
SET(RubyModular ON CACHE BOOL "Ruby Modular")
UNSET(TARGET_SWIGFLAGS)
#FIND_PACKAGE(RubyNArray)
add_subdirectory(src/interfaces/ruby_modular)
ENDIF()

FIND_PACKAGE(Lua51)
IF(LUA51_FOUND)
UNSET(TARGET_SWIGFLAGS)
add_subdirectory(src/interfaces/lua_modular)
ENDIF()

FIND_PACKAGE(Octave)
IF(OCTAVE_LIBRARIES)
UNSET(TARGET_SWIGFLAGS)
add_subdirectory(src/interfaces/octave_modular)
ENDIF()

FIND_PACKAGE(CSharp)
IF(CSHARP_FOUND)
UNSET(TARGET_SWIGFLAGS)
add_subdirectory(src/interfaces/csharp_modular)
ENDIF()

#FIND_PACKAGE(R)
ENDIF()

Expand All @@ -431,3 +458,7 @@ SET(COMPFLAGS_CPP "TODO")
SET(LINKFLAGS "TODO")

add_subdirectory(src/shogun)

IF(BUILD_EXAMPLES)

ENDIF()
5 changes: 4 additions & 1 deletion cmake/CommonModularInterface.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ FOREACH(file ${MODULAR_FILES})
list(APPEND modular_files ${fname})
ADD_CUSTOM_COMMAND(OUTPUT ${fname}
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${file} ${fname}
COMMENT ""
)
ENDFOREACH()

Expand All @@ -22,7 +23,9 @@ ADD_CUSTOM_TARGET(${MODULAR_NAME}_modular_src

INCLUDE(${SWIG_USE_FILE})
SET_SOURCE_FILES_PROPERTIES(modshogun.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(modshogun.i PROPERTIES SWIG_FLAGS ${TARGET_SWIGFLAGS})
IF(DEFINED TARGET_SWIGFLAGS)
SET_SOURCE_FILES_PROPERTIES(modshogun.i PROPERTIES SWIG_FLAGS ${TARGET_SWIGFLAGS})
ENDIF()
SWIG_ADD_MODULE(${MODULAR_NAME}_modular ${MODULAR_NAME} modshogun.i sg_print_functions.cpp)
SWIG_LINK_LIBRARIES(${MODULAR_NAME}_modular shogun ${MODULAR_LIBARIES})
ADD_DEPENDENCIES(${PREPEND_TARGET}${MODULAR_NAME}_modular ${MODULAR_NAME}_modular_src)
Expand Down
6 changes: 6 additions & 0 deletions cmake/FindApacheAnt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
find_file(ANT_EXECUTABLE NAMES ant ant.sh ant.bat PATHS $ENV{ANT_HOME}/bin)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ANT DEFAULT_MSG ANT_EXECUTABLE)

MARK_AS_ADVANCED(ANT_EXECUTABLE)
72 changes: 72 additions & 0 deletions cmake/FindCSharp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# A CMake Module for finding and using C# (.NET and Mono).
#
# The following variables are set:
# CSHARP_FOUND - set to ON if C# is found
# CSHARP_USE_FILE - the path to the C# use file
# CSHARP_TYPE - the type of the C# compiler (eg. ".NET" or "Mono")
# CSHARP_VERSION - the version of the C# compiler (eg. "v4.0" or "2.10.2")
# CSHARP_COMPILER - the path to the C# compiler executable (eg. "C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe" or "/usr/bin/gmcs")
# CSHARP_INTERPRETER - the path to interpreter needed to run CSharp executables
# CSHARP_PLATFORM - the C# target platform
# CSHARP_SDK - the SDK commandline switch (empty for .NET, for Mono eg. "/sdk:2" or "/sdk:4")
#
# This file is based on the work of GDCM:
# http://gdcm.svn.sf.net/viewvc/gdcm/trunk/CMake/FindCSharp.cmake
# Copyright (c) 2006-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#

# TODO: ADD ABILITY TO SELECT WHICH C# COMPILER eg. .NET or Mono (if both exist). For the moment, .NET is selected above Mono.

# Make sure find package macros are included
include( FindPackageHandleStandardArgs )

unset( CSHARP_COMPILER CACHE )
unset( CSHARP_INTERPRETER CACHE )
unset( CSHARP_TYPE CACHE )
unset( CSHARP_VERSION CACHE )
unset( CSHARP_FOUND CACHE )

# By default use anycpu platform, allow the user to override
set( CSHARP_PLATFORM "anycpu" CACHE STRING "C# target platform: x86, x64, anycpu, or itanium" )
if( NOT ${CSHARP_PLATFORM} MATCHES "x86|x64|anycpu|itanium" )
message( FATAL_ERROR "The C# target platform '${CSHARP_PLATFORM}' is not valid. Please enter one of the following: x86, x64, anycpu, or itanium" )
endif( )

if( WIN32 )
find_package( DotNetFrameworkSdk )
if( NOT CSHARP_DOTNET_FOUND )
find_package( Mono )
endif( )
else( UNIX )
find_package( Mono )
endif( )

if( CSHARP_DOTNET_FOUND )
set( CSHARP_TYPE ".NET" CACHE STRING "Using the .NET compiler" )
set( CSHARP_VERSION ${CSHARP_DOTNET_VERSION} CACHE STRING "C# .NET compiler version" FORCE )
set( CSHARP_COMPILER ${CSHARP_DOTNET_COMPILER_${CSHARP_DOTNET_VERSION}} CACHE STRING "Full path to .NET compiler" FORCE )
set( CSHARP_INTERPRETER "" CACHE INTERNAL "Interpretor not required for .NET" FORCE )
elseif( CSHARP_MONO_FOUND )
set( CSHARP_TYPE "Mono" CACHE STRING "Using the Mono compiler" )
set( CSHARP_VERSION ${CSHARP_MONO_VERSION} CACHE STRING "C# Mono compiler version" FORCE )
set( CSHARP_COMPILER ${CSHARP_MONO_COMPILER_${CSHARP_MONO_VERSION}} CACHE STRING "Full path to Mono compiler" FORCE )
set( CSHARP_INTERPRETER ${CSHARP_MONO_INTERPRETER_${CSHARP_MONO_VERSION}} CACHE STRING "Full path to Mono interpretor" FORCE )
set( CSHARP_SDK "/sdk:2" CACHE STRING "C# Mono SDK commandline switch (e.g. /sdk:2, /sdk:4, /sdk:5)" )
endif( )

# Handle WIN32 specific issues
if ( WIN32 )
if ( CSHARP_COMPILER MATCHES "bat" )
set( CSHARP_COMPILER "call ${CSHARP_COMPILER}" )
endif ( )
endif( )

FIND_PACKAGE_HANDLE_STANDARD_ARGS(CSharp DEFAULT_MSG CSHARP_TYPE CSHARP_VERSION CSHARP_COMPILER)

mark_as_advanced( CSHARP_TYPE CSHARP_VERSION CSHARP_COMPILER CSHARP_INTERPRETER CSHARP_PLATFORM CSHARP_SDK )

# Set the USE_FILE path
# http://public.kitware.com/Bug/view.php?id=7757
get_filename_component( current_list_path ${CMAKE_CURRENT_LIST_FILE} PATH )
set( CSHARP_USE_FILE ${current_list_path}/UseCSharp.cmake )
91 changes: 91 additions & 0 deletions cmake/FindDotNetFrameworkSdk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# A CMake Module for finding C# .NET.
#
# The following variables are set:
# CSHARP_DOTNET_FOUND
# CSHARP_DOTNET_COMPILER_${version} eg. "CSHARP_DOTNET_COMPILER_v4.0.30319"
# CSHARP_DOTNET_VERSION eg. "v4.0.30319"
# CSHARP_DOTNET_VERSIONS eg. "v2.0.50727, v3.5, v4.0.30319"
# DotNetFrameworkSdk_USE_FILE
#
# Additional references can be found here:
# .NET SDK 1.1: http://www.microsoft.com/downloads/details.aspx?FamilyID=9b3a2ca6-3647-4070-9f41-a333c6b9181d&displaylang=en
# .NET SDK 2.0: http://www.microsoft.com/downloads/details.aspx?FamilyID=fe6f2099-b7b4-4f47-a244-c96d69c35dec&displaylang=en
# .NET SDK 3.5: http://www.microsoft.com/downloads/details.aspx?familyid=333325fd-ae52-4e35-b531-508d977d32a6&displaylang=en
# C# Compiler options: http://msdn.microsoft.com/en-us/library/2fdbz5xd(v=VS.71).aspx
#
# This file is based on the work of GDCM:
# http://gdcm.svn.sf.net/viewvc/gdcm/trunk/CMake/FindDotNETFrameworkSDK.cmake
# Copyright (c) 2006-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#

set( csharp_dotnet_valid 1 )
if( DEFINED CSHARP_DOTNET_FOUND )
# The .NET compiler has already been found
# It may have been reset by the user, verify it is correct
if( NOT DEFINED CSHARP_DOTNET_COMPILER_${CSHARP_DOTNET_VERSION} )
set( csharp_dotnet_version_user ${CSHARP_DOTNET_VERSION} )
set( csharp_dotnet_valid 0 )
set( CSHARP_DOTNET_FOUND 0 )
set( CSHARP_DOTNET_VERSION "CSHARP_DOTNET_VERSION-NOTVALID" CACHE STRING "C# .NET compiler version, choices: ${CSHARP_DOTNET_VERSIONS}" FORCE )
message( FATAL_ERROR "The C# .NET version '${csharp_dotnet_version_user}' is not valid. Please enter one of the following: ${CSHARP_DOTNET_VERSIONS}" )
endif( )
endif( )

unset( CSHARP_DOTNET_VERSIONS CACHE ) # Clear versions

# Get the framework directory based on platform
if( ${CSHARP_PLATFORM} MATCHES "x64|itanium" )
set( csharp_dotnet_framework_dir "$ENV{windir}/Microsoft.NET/Framework64" )
else( )
set( csharp_dotnet_framework_dir "$ENV{windir}/Microsoft.NET/Framework" )
endif( )

# Search for .NET versions
string( REPLACE "\\" "/" csharp_dotnet_framework_dir ${csharp_dotnet_framework_dir} )
file( GLOB_RECURSE csharp_dotnet_executables "${csharp_dotnet_framework_dir}/csc.exe" )
list( SORT csharp_dotnet_executables )
list( REVERSE csharp_dotnet_executables )
foreach ( csharp_dotnet_executable ${csharp_dotnet_executables} )
if( csharp_dotnet_valid )
# Extract version number (eg. v4.0.30319)
# TODO: Consider using REGEX
string( REPLACE "${csharp_dotnet_framework_dir}/" "" csharp_dotnet_version_temp ${csharp_dotnet_executable} )
string( REPLACE "/csc.exe" "" csharp_dotnet_version_temp ${csharp_dotnet_version_temp} )

# Add variable holding executable
set( CSHARP_DOTNET_COMPILER_${csharp_dotnet_version_temp} ${csharp_dotnet_executable} CACHE STRING "C# .NET compiler ${csharp_dotnet_version}" FORCE )
mark_as_advanced( CSHARP_DOTNET_COMPILER_${csharp_dotnet_version_temp} )
endif( )

# Create a list of supported compiler versions
if( NOT DEFINED CSHARP_DOTNET_VERSIONS )
set( CSHARP_DOTNET_VERSIONS "${csharp_dotnet_version_temp}" CACHE STRING "Available C# .NET compiler versions" FORCE )
else( )
set( CSHARP_DOTNET_VERSIONS "${CSHARP_DOTNET_VERSIONS}, ${csharp_dotnet_version_temp}" CACHE STRING "Available C# .NET compiler versions" FORCE )
endif( )
mark_as_advanced( CSHARP_DOTNET_VERSIONS )

# We found at least one .NET compiler version
set( CSHARP_DOTNET_FOUND 1 CACHE INTERNAL "Boolean indicating if C# .NET was found" )
endforeach( csharp_dotnet_executable )

if( CSHARP_DOTNET_FOUND )
# Report the found versions
message( STATUS "Found the following C# .NET versions: ${CSHARP_DOTNET_VERSIONS}" )

# Set the compiler version
# Do not force, so that the user can manually select their own version if they wish
if ( DEFINED CSHARP_DOTNET_COMPILER_v2.0.50727 )
# If available, select .NET v2.0.50727 (this is the minimal version as it supports generics, and allows use of VS2008)
set( CSHARP_DOTNET_VERSION "v2.0.50727" CACHE STRING "C# .NET compiler version" )
else( )
# Select the highest version (first in reverse sorted list)
list( GET CSHARP_DOTNET_VERSIONS 0 csharp_dotnet_version_temp )
set( CSHARP_DOTNET_VERSION ${csharp_dotnet_version_temp} CACHE STRING "C# .NET compiler version" )
endif( )
mark_as_advanced( CSHARP_DOTNET_VERSION )
endif( )

# Set USE_FILE
get_filename_component( current_list_path ${CMAKE_CURRENT_LIST_FILE} PATH )
set( DotNetFrameworkSdk_USE_FILE ${current_list_path}/UseDotNetFrameworkSdk.cmake )
Loading

0 comments on commit 54232cc

Please sign in to comment.