~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to CMake/UseCSharp.cmake

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# A CMake Module for finding and using C# (.NET and Mono).
 
3
#
 
4
# The following global variables are assumed to exist:
 
5
#   CSHARP_SOURCE_DIRECTORY - path to C# sources
 
6
#   CSHARP_BINARY_DIRECTORY - path to place resultant C# binary files
 
7
#
 
8
# The following variables are set:
 
9
#   CSHARP_TYPE - the type of the C# compiler (eg. ".NET" or "Mono")
 
10
#   CSHARP_COMPILER - the path to the C# compiler executable (eg. "C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe")
 
11
#   CSHARP_VERSION - the version number of the C# compiler (eg. "v4.0.30319")
 
12
#
 
13
# The following macros are defined:
 
14
#   CSHARP_ADD_EXECUTABLE( name references [files] [output_dir] ) - Define C# executable with the given name
 
15
#   CSHARP_ADD_LIBRARY( name references [files] [output_dir] ) - Define C# library with the given name
 
16
#
 
17
# Examples:
 
18
#   CSHARP_ADD_EXECUTABLE( MyExecutable "" "Program.cs" )
 
19
#   CSHARP_ADD_EXECUTABLE( MyExecutable "ref1.dll ref2.dll" "Program.cs File1.cs" )
 
20
#   CSHARP_ADD_EXECUTABLE( MyExecutable "ref1.dll;ref2.dll" "Program.cs;File1.cs" )
 
21
#
 
22
# This file is based on the work of GDCM:
 
23
#   http://gdcm.svn.sf.net/viewvc/gdcm/trunk/CMake/UseCSharp.cmake
 
24
# Copyright (c) 2006-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
 
25
#
 
26
 
 
27
# TODO: ADD SUPPORT FOR LINK LIBRARIES
 
28
 
 
29
# Check something was found
 
30
if( NOT CSHARP_COMPILER )
 
31
  message( WARNING "A C# compiler executable was not found on your system" )
 
32
endif( NOT CSHARP_COMPILER )
 
33
 
 
34
# Include type-based USE_FILE
 
35
if( CSHARP_TYPE MATCHES ".NET" )
 
36
  include( ${DotNetFrameworkSdk_USE_FILE} )
 
37
elseif ( CSHARP_TYPE MATCHES "Mono" )
 
38
  include( ${Mono_USE_FILE} )
 
39
endif ( CSHARP_TYPE MATCHES ".NET" )
 
40
 
 
41
macro( CSHARP_ADD_LIBRARY name )
 
42
  CSHARP_ADD_PROJECT( "library" ${name} ${ARGN} )
 
43
endmacro( CSHARP_ADD_LIBRARY )
 
44
 
 
45
macro( CSHARP_ADD_EXECUTABLE name )
 
46
  CSHARP_ADD_PROJECT( "exe" ${name} ${ARGN} )
 
47
endmacro( CSHARP_ADD_EXECUTABLE )
 
48
 
 
49
# Private macro
 
50
macro( CSHARP_ADD_PROJECT type name )
 
51
  set( refs "/reference:System.dll" )
 
52
  set( sources )
 
53
  set( sources_dep )
 
54
 
 
55
  if( ${type} MATCHES "library" )
 
56
    set( output "dll" )
 
57
  elseif( ${type} MATCHES "exe" )
 
58
    set( output "exe" )
 
59
  endif( ${type} MATCHES "library" )
 
60
 
 
61
  # Step through each argument
 
62
  foreach( it ${ARGN} )
 
63
    if( ${it} MATCHES "(.*)(dll)" )
 
64
       # Argument is a dll, add reference
 
65
       list( APPEND refs /reference:${it} )
 
66
    else( )
 
67
      # Argument is a source file
 
68
      if( EXISTS ${it} )
 
69
        list( APPEND sources ${it} )
 
70
        list( APPEND sources_dep ${it} )
 
71
      elseif( EXISTS ${CSHARP_SOURCE_DIRECTORY}/${it} )
 
72
        list( APPEND sources ${CSHARP_SOURCE_DIRECTORY}/${it} )
 
73
        list( APPEND sources_dep ${CSHARP_SOURCE_DIRECTORY}/${it} )
 
74
      elseif( ${it} MATCHES "[*]" )
 
75
        # For dependencies, we need to expand wildcards
 
76
        FILE( GLOB it_glob ${it} )
 
77
        list( APPEND sources ${it} )
 
78
        list( APPEND sources_dep ${it_glob} )
 
79
      elseif( IS_ABSOLUTE ${it} )
 
80
        list( APPEND sources ${it} )
 
81
        list( APPEND sources_dep ${it} )
 
82
      endif( )
 
83
    endif ( )
 
84
  endforeach( )
 
85
 
 
86
  # Check we have at least one source
 
87
  list( LENGTH sources_dep sources_length )
 
88
  if ( ${sources_length} LESS 1 )
 
89
    MESSAGE( SEND_ERROR "No C# sources were specified for ${type} ${name}" )
 
90
  endif ()
 
91
  list( SORT sources_dep )
 
92
 
 
93
  # Perform platform specific actions
 
94
  if (WIN32)
 
95
    string( REPLACE "/" "\\" sources ${sources} )
 
96
  else (UNIX)
 
97
    string( REPLACE "\\" "/" sources ${sources} )
 
98
  endif (WIN32)
 
99
 
 
100
  # Add custom target and command
 
101
  # MESSAGE( STATUS "Adding C# ${type} ${name}: '${CSHARP_COMPILER} /t:${type} /out:${name}.${output} /platform:${CSHARP_PLATFORM} ${CSHARP_SDK} ${refs} ${sources}'" )
 
102
  add_custom_command(
 
103
    COMMENT "Compiling C# ${type} ${name}: '${CSHARP_COMPILER} /t:${type} /out:${name}.${output} /platform:${CSHARP_PLATFORM} ${CSHARP_SDK} ${refs} ${sources}'"
 
104
    OUTPUT ${CSHARP_BINARY_DIRECTORY}/${name}.${output}
 
105
    COMMAND ${CSHARP_COMPILER}
 
106
    ARGS /t:${type} /out:${name}.${output} /platform:${CSHARP_PLATFORM} ${CSHARP_SDK} ${refs} ${sources}
 
107
    WORKING_DIRECTORY ${CSHARP_BINARY_DIRECTORY}
 
108
    DEPENDS ${sources_dep}
 
109
  )
 
110
  add_custom_target(
 
111
    ${name} ALL
 
112
    DEPENDS ${CSHARP_BINARY_DIRECTORY}/${name}.${output}
 
113
    SOURCES ${sources_dep}
 
114
  )
 
115
endmacro( CSHARP_ADD_PROJECT )