CMakeLists.txt 4.78 KB
Newer Older
1
PROJECT(campvis-scripting)
2
MESSAGE(STATUS "Configuring CAMPVis-Scripting")
3

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

9

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

FILE(GLOB CampvisScriptingHeaders
    *.h
19
    glue/*.h
20
21
	luagen/*.h
	luagen/properties/*.h
22
23
)

24
IF(WIN32)
25
    #LIST(APPEND CampvisScriptingDefinitions "/wd4267")
26
27
ENDIF(WIN32)

28
29
30
31
32
33
34

# 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.
35
LIST(APPEND CampvisGlobalDefinitions "-DCAMPVIS_LUA_MODS_PATH=\"${CampvisLuaModulesDirectory}?${CMAKE_SHARED_MODULE_SUFFIX}\"")
36
LIST(APPEND CampvisGlobalDefinitions "-DCAMPVIS_LUA_SCRIPTS_PATH=\"${CampvisLuaModulesDirectory}?.lua\"")
37
SET(CampvisGlobalDefinitions "${CampvisGlobalDefinitions}" PARENT_SCOPE)
38

39
SET(CampvisBindingDirs ext/cgt core application)
40
41
42
43
44
45
46
47
48
49
50
51
52
53

# 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}")
    ENDIF(CAMPVIS_BUILD_MODULE_${ModNameUpper})
ENDFOREACH(ModName ${CampvisModules})

# 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")
54
    MESSAGE(STATUS " - ${LuaModShortName}")
55

56
57
58
59
    IF(WIN32)
        ADD_DEFINITIONS("/wd4244 /wd4267")
    ENDIF()
    
60
61
    SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES CPLUSPLUS ON)
    SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES SWIG_FLAGS "-I${CampvisHome}")
62
    LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
63
    SWIG_ADD_MODULE(${LuaModName} lua ${InterfaceFile})
64
    SWIG_LINK_LIBRARIES(${LuaModName} cgt campvis-core campvis-modules campvis-application-lib ${CampvisGlobalExternalLibs})
65

66
    SET(LuaModFullPath "${CampvisLuaModulesDirectory}${LuaModShortName}${CMAKE_SHARED_LIBRARY_SUFFIX}")
67
68
69
70
71
72

    # 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(
73
        TARGET ${LuaModName}
74
75
        POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E make_directory ${CampvisLuaModulesDirectory}
76
        COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${LuaModName}> ${LuaModFullPath}
77
    )
78
79
80
81

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

82
MESSAGE(STATUS "* Setting up Lua modules:")
83
84
85
86
87
88
89
90
91
92

# 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})
93

94

95
96
# Generate header with SWIG run-time functions
ADD_CUSTOM_COMMAND(
97
   OUTPUT "swigluarun.h"
98
99
100
   COMMAND ${SWIG_EXECUTABLE} -c++ -lua -external-runtime "swigluarun.h"
 )

101
102
103
104
LIST(APPEND CampvisScriptingHeaders "swigluarun.h")

ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisScriptingDefinitions})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CMAKE_CURRENT_BINARY_DIR})
105
LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
106

107
ADD_LIBRARY(campvis-scripting ${CampvisScriptingSources} ${CampvisScriptingHeaders})
Hossain Mahmud's avatar
Hossain Mahmud committed
108
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules cgt ${CampvisGlobalExternalLibs})
109

110
111
112
113
# if campvis-core is built as a shared library, CMake will define the following flag to instruct
# the code to export DLL symbols
SET_TARGET_PROPERTIES(campvis-scripting PROPERTIES DEFINE_SYMBOL "CAMPVIS_SCRIPTING_BUILD_DLL")

114
115
116
117
IF(CAMPVIS_GROUP_SOURCE_FILES)
    DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisScriptingSources ${CampvisHome} "")
    DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisScriptingHeaders ${CampvisHome} "")
ENDIF()
118
119

INSTALL(TARGETS campvis-scripting DESTINATION exports EXPORT campvis-targets)