Menu

[acc09d]: / UseCSharp.cmake  Maximize  Restore  History

Download this file

118 lines (104 with data), 4.7 kB

  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
#
# A CMake Module for finding and using C# (.NET and Mono).
#
# The following global variables are assumed to exist:
# CSHARP_SOURCE_DIRECTORY - path to C# sources
# CSHARP_BINARY_DIRECTORY - path to place resultant C# binary files
#
# The following variables are set:
# CSHARP_TYPE - the type of the C# compiler (eg. ".NET" or "Mono")
# CSHARP_COMPILER - the path to the C# compiler executable (eg. "C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe")
# CSHARP_VERSION - the version number of the C# compiler (eg. "v4.0.30319")
#
# The following macros are defined:
# CSHARP_ADD_EXECUTABLE( name references [files] [output_dir] ) - Define C# executable with the given name
# CSHARP_ADD_LIBRARY( name references [files] [output_dir] ) - Define C# library with the given name
#
# Examples:
# CSHARP_ADD_EXECUTABLE( MyExecutable "" "Program.cs" )
# CSHARP_ADD_EXECUTABLE( MyExecutable "ref1.dll ref2.dll" "Program.cs File1.cs" )
# CSHARP_ADD_EXECUTABLE( MyExecutable "ref1.dll;ref2.dll" "Program.cs;File1.cs" )
#
# This file is based on the work of GDCM:
# http://gdcm.svn.sf.net/viewvc/gdcm/trunk/CMake/UseCSharp.cmake
# Copyright (c) 2006-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# TODO: ADD SUPPORT FOR LINK LIBRARIES
# Check something was found
if( NOT CSHARP_COMPILER )
message( WARNING "A C# compiler executable was not found on your system" )
endif( NOT CSHARP_COMPILER )
# Include type-based USE_FILE
if( CSHARP_TYPE MATCHES ".NET" )
include( ${DotNetFrameworkSdk_USE_FILE} )
elseif ( CSHARP_TYPE MATCHES "Mono" )
include( ${Mono_USE_FILE} )
endif ( CSHARP_TYPE MATCHES ".NET" )
macro( CSHARP_ADD_LIBRARY name )
CSHARP_ADD_PROJECT( "library" ${name} ${ARGN} )
endmacro( CSHARP_ADD_LIBRARY )
macro( CSHARP_ADD_EXECUTABLE name )
CSHARP_ADD_PROJECT( "exe" ${name} ${ARGN} )
endmacro( CSHARP_ADD_EXECUTABLE )
#--------------------------------------------------------------------------------------------------
# Macro created by Noel Lopes (noel@ipg.pt)
#--------------------------------------------------------------------------------------------------
macro(CSHARP_ADD_WINAPP name)
CSHARP_ADD_PROJECT("winexe" ${name} ${ARGN})
endmacro(CSHARP_ADD_WINAPP)
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
# Private Macro changed by Noel Lopes (noel@ipg.pt)
#--------------------------------------------------------------------------------------------------
macro( CSHARP_ADD_PROJECT type name )
set( refs "/reference:System.dll" )
set( sources )
set( sources_dep )
if(${type} MATCHES "library")
set( output "dll" )
elseif(${type} MATCHES "exe" OR ${type} MATCHES "winexe")
set( output "exe" )
endif()
# Step through each argument
foreach( it ${ARGN} )
if( ${it} MATCHES "(.*)(dll)" )
# Argument is a dll, add reference
list( APPEND refs /reference:${it} )
else( )
# Argument is a source file
set(filename "")
if( EXISTS ${it} )
set(filename "${it}")
elseif( EXISTS ${CSHARP_SOURCE_DIRECTORY}/${it} )
set(filename "${CSHARP_SOURCE_DIRECTORY}/${it}")
elseif( ${it} MATCHES "[*]" )
# For dependencies, we need to expand wildcards
FILE( GLOB it_glob ${it} )
list( APPEND sources ${it} )
list( APPEND sources_dep ${it_glob} )
else()
message(WARNING "Could not find file ${it}.")
endif()
if (NOT "${filename}" STREQUAL "")
list(APPEND sources ${filename})
list(APPEND sources_dep ${filename})
endif()
endif ( )
endforeach( )
# Check we have at least one source
list( LENGTH sources_dep sources_length )
if ( ${sources_length} LESS 1 )
MESSAGE( SEND_ERROR "No C# sources were specified for ${type} ${name}" )
endif ()
list( SORT sources_dep )
# Add custom target and command
MESSAGE(STATUS "Adding C# ${type} ${name}: '${CSHARP_COMPILER} /t:${type} /out:${name}.${output} /platform:${CSHARP_PLATFORM} ${refs} ${sources}'" )
add_custom_target(
${name} ALL
COMMAND ${CSHARP_COMPILER} /t:${type} /out:${CSHARP_BINARY_DIRECTORY}/${name}.${output} /platform:${CSHARP_PLATFORM} ${refs} ${sources}
WORKING_DIRECTORY ${CSHARP_SOURCE_DIRECTORY}
COMMENT "Compiling C# ${type} ${name}: '${CSHARP_COMPILER} /t:${type} /out:${CSHARP_BINARY_DIRECTORY}/${name}.${output} /platform:${CSHARP_PLATFORM} ${refs} ${sources}'"
SOURCES ${sources_dep}
)
endmacro( CSHARP_ADD_PROJECT )
#--------------------------------------------------------------------------------------------------
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.