summaryrefslogtreecommitdiff
path: root/src/csharp/CMakeLists.txt
blob: 0e2bc00abd1429066038121449ce6aa0a7f24f81 (plain)
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
# Generate C# wrapper
include_directories(../)

# Compile CSHARP Bindings
find_program(GMCS NAMES gmcs HINTS /usr/bin/)

if (NOT GMCS)
    #The following assumes windows, so we exit otherwise
    message("gmcs not found, not building csharp bindings")
    return()
endif()

set(KOLAB_SWIG_CSHARP_SOURCE_FILE ${CMAKE_CURRENT_BINARY_DIR}/csharp_kolabformat_wrapper.cpp) #it seems we never use this file? it works at least as a dependecy.
set(KOLAB_SWIG_CSHARP_DLL_FILE ${CMAKE_CURRENT_BINARY_DIR}/kolabformat.dll)
set(KOLAB_SWIG_CSHARP_TEST_FILE ${CMAKE_CURRENT_BINARY_DIR}/test.exe)

add_custom_command(OUTPUT ${KOLAB_SWIG_CSHARP_SOURCE_FILE}
        COMMAND ${SWIG} -v -c++ -csharp -o ${KOLAB_SWIG_CSHARP_SOURCE_FILE}  ../kolabformat.i
        COMMENT "Generating C# bindings"
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        DEPENDS ../kolabformat.i kolabxml
        VERBATIM
    )

SET_SOURCE_FILES_PROPERTIES(${KOLAB_SWIG_CSHARP_SOURCE_FILE} PROPERTIES GENERATED 1)

configure_file(test.cs ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)

FILE(GLOB CSHARP_GENERATED_SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.cs")
LIST( REMOVE_ITEM CSHARP_GENERATED_SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/kolabformat.cs") #this one must be first so we remove and readd later
SET_SOURCE_FILES_PROPERTIES(${CSHARP_GENERATED_SOURCE_FILES} PROPERTIES GENERATED 1)
LIST( REMOVE_ITEM CSHARP_GENERATED_SOURCE_FILES "${CMAKE_CURRENT_BINARY_DIR}/test.cs") #not a generated file

add_custom_command(OUTPUT ${KOLAB_SWIG_CSHARP_DLL_FILE}
        COMMAND ${GMCS} -target:library "${CMAKE_CURRENT_BINARY_DIR}/kolabformat.cs" ${CSHARP_GENERATED_SOURCE_FILES}
        COMMENT "Compiling C# library"
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        DEPENDS kolabxml ${KOLAB_SWIG_CSHARP_SOURCE_FILE} ${CSHARP_GENERATED_SOURCE_FILES}
        VERBATIM
    )

add_custom_command(OUTPUT ${KOLAB_SWIG_CSHARP_TEST_FILE}
        COMMAND ${GMCS} -reference:${KOLAB_SWIG_CSHARP_DLL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/test.cs
        COMMENT "Compiling C# test.exe"
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        DEPENDS kolabxml ${KOLAB_SWIG_CSHARP_SOURCE_FILE} ${KOLAB_SWIG_CSHARP_DLL_FILE}
        VERBATIM
    )

SET_SOURCE_FILES_PROPERTIES(${KOLAB_SWIG_CSHARP_DLL_FILE} PROPERTIES GENERATED 1)
SET_SOURCE_FILES_PROPERTIES(${KOLAB_SWIG_CSHARP_TEST_FILE} PROPERTIES GENERATED 1)
ADD_CUSTOM_TARGET(generate_csharp_bindings ALL DEPENDS ${KOLAB_SWIG_CSHARP_DLL_FILE} ${KOLAB_SWIG_CSHARP_TEST_FILE})

if (KOLAB_CSHARP_INSTALL_DIR)
    set(CSHARP_INSTALL_DIR ${KOLAB_CSHARP_INSTALL_DIR})
else (KOLAB_CSHARP_INSTALL_DIR)
    set(CSHARP_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/csharpbindings)
endif (KOLAB_CSHARP_INSTALL_DIR)

#not sure about the LIBRARY here, but might work
install(FILES ${KOLAB_SWIG_CSHARP_DLL_FILE} LIBRARY DESTINATION ${CSHARP_INSTALL_DIR})
install(FILES ${KOLAB_SWIG_CSHARP_TEST_FILE} RUNTIME DESTINATION ${CSHARP_INSTALL_DIR})