CMakeLists.txt 4.97 KB
Newer Older
1
2
3
4
5
PROJECT(campvis-scripting)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)

MESSAGE(STATUS "Configuring CAMPVis Scripting")

6
7
8
9
10
# SWIG
FIND_PACKAGE(SWIG REQUIRED)
MESSAGE(STATUS "* Found SWIG")
INCLUDE(${SWIG_USE_FILE})

11

12
13
FILE(GLOB CampvisScriptingSources
    *.cpp
14
    glue/*.cpp
15
16
17
18
)

FILE(GLOB CampvisScriptingHeaders
    *.h
19
    glue/*.h
20
21
)

22
23
24
25
IF(WIN32)
    LIST(APPEND CampvisScriptingDefinitions /wd4267)
ENDIF(WIN32)

26
27
28
29
30
31
32

# Place all of CAMPVis' Lua modules in one sub-directory and shorten their names. This is done to
# make Lua modules easier to import and avoid mixing them with other CAMPVis' libraries.
SET(CampvisLuaModulesDirectory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/lua-mods/")

# Lua modules will be placed in a sub-directory that won't be picked up by Lua automatically. Let
# the code know via a #define what that sub-directory is so that it can instruct Lua to search it.
33
LIST(APPEND CampvisGlobalDefinitions "-DCAMPVIS_LUA_MODS_PATH=\"${CampvisLuaModulesDirectory}?${CMAKE_SHARED_MODULE_SUFFIX}\"")
34
LIST(APPEND CampvisGlobalDefinitions "-DCAMPVIS_LUA_SCRIPTS_PATH=\"${CampvisLuaModulesDirectory}?.lua\"")
35
SET(CampvisGlobalDefinitions "${CampvisGlobalDefinitions}" PARENT_SCOPE)
36

37
SET(CampvisBindingDirs ext/cgt core)
38
39
40
41
42
43
44

# Look for bindings for all enabled CAMPVis modules
FOREACH(ModName ${CampvisModules})
    STRING(TOUPPER ${ModName} ModNameUpper)

    IF(CAMPVIS_BUILD_MODULE_${ModNameUpper})
        LIST(APPEND CampvisBindingDirs "modules/${ModName}")
45
46
47

        FILE(GLOB ModLuaPipelines "${CampvisHome}/modules/${ModName}/pipelines/*.lua")
        LIST(APPEND CampvisLuaPipelines ${ModLuaPipelines})
48
49
50
    ENDIF(CAMPVIS_BUILD_MODULE_${ModNameUpper})
ENDFOREACH(ModName ${CampvisModules})

51
52
53
54
55
56
57
# Hack-fix for a bug in SWIG_ADD_MODULE that breaks out-of-tree builds by not creating wrapper
# output directories.
# TODO: remove once http://www.cmake.org/Bug/view.php?id=14459 lands
FOREACH(BindingDir ${CampvisBindingDirs})
    FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${BindingDir}/bindings")
ENDFOREACH(BindingDir ${CampvisBindingDirs})

58
59
60
61
62
63
64
65
66

# Declare a Lua module to be generated by SWIG from the specified interface file
MACRO(DECLARE_LUA_MODULE InterfaceFile)
    STRING(REGEX REPLACE ".*/([A-Za-z0-9_]+)\\.i" "\\1" LuaModShortName ${InterfaceFile})
    SET(LuaModName "${LuaModShortName}-lua-mod")
    MESSAGE(STATUS "* ${LuaModShortName}")

    SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES CPLUSPLUS ON)
    SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES SWIG_FLAGS "-I${CampvisHome}")
67
    LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
68
    SWIG_ADD_MODULE(${LuaModName} lua ${InterfaceFile})
69
    SWIG_LINK_LIBRARIES(${LuaModName} cgt campvis-core campvis-modules ${CampvisGlobalExternalLibs})
70

71
    SET(LuaModFullPath "${CampvisLuaModulesDirectory}${LuaModShortName}${CMAKE_SHARED_LIBRARY_SUFFIX}")
72
73
74
75
76
77

    # The most reliable approach to changing a target's output directory to a sub-directory of the
    # main build folder if a multi-config generator (e.g. Visual Studio or XCode) may be used is
    # to invoke a custom command to copy the necessary files after the build finishes. For more
    # details see: http://www.cmake.org/pipermail/cmake/2008-June/022358.html
    ADD_CUSTOM_COMMAND(
78
        TARGET ${LuaModName}
79
80
        POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E make_directory ${CampvisLuaModulesDirectory}
81
        COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${LuaModName}> ${LuaModFullPath}
82
    )
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

    LIST(APPEND CampvisLuaModules ${LuaModName})
ENDMACRO(DECLARE_LUA_MODULE)

MESSAGE(STATUS "Setting up Lua modules:")

# Generate a Lua module for every interface file found
FOREACH(BindingDir ${CampvisBindingDirs})
    FILE(GLOB InterfaceFiles "${CampvisHome}/${BindingDir}/bindings/*.i")

    FOREACH(InterfaceFile ${InterfaceFiles})
        FILE(RELATIVE_PATH InterfaceFileRelativePath ${CMAKE_CURRENT_SOURCE_DIR} ${InterfaceFile})
        DECLARE_LUA_MODULE(${InterfaceFileRelativePath})
    ENDFOREACH(InterfaceFile ${InterfaceFiles})
ENDFOREACH(BindingDir ${CampvisBindingDirs})
98

99

100
101
102
103
104
105
106
107
# Generate a registration header for Lua pipelines
FOREACH(LuaPipeline ${CampvisLuaPipelines})
    PARSE_SCRIPT_FOR_PIPELINE(${LuaPipeline})
ENDFOREACH(LuaPipeline ${CampvisBindingDirs})

WRITE_SCRIPTED_PIPELINE_REGISTRATION("gen_pipelineregistration.h")


108
109
# Generate header with SWIG run-time functions
ADD_CUSTOM_COMMAND(
110
   OUTPUT "swigluarun.h"
111
112
113
   COMMAND ${SWIG_EXECUTABLE} -c++ -lua -external-runtime "swigluarun.h"
 )

114
115
116
117
LIST(APPEND CampvisScriptingHeaders "swigluarun.h")

ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisScriptingDefinitions})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CMAKE_CURRENT_BINARY_DIR})
118
LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
119

120
121

ADD_LIBRARY(campvis-scripting ${CampvisSharedStaticModulesFix}
122
123
    ${CampvisScriptingSources} ${CampvisScriptingHeaders}
)
124

125
ADD_DEPENDENCIES(campvis-scripting ${CampvisLuaModules})
126
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules cgt ${CampvisGlobalExternalLibs})