Fixed a few issues, everything now works again.
[fail.git] / libs / CMakeLists.txt
blobce54e17629ea309b613a134f05150b2d61c4aaa7
2 #   Fail game engine
3 #   Copyright 2007-2008 Antoine Chavasse <a.chavasse@gmail.com>
4
5 #   This file is part of Fail.
7 #   Fail is free software; you can redistribute it and/or modify
8 #   it under the terms of the GNU General Public License version 3
9 #   as published by the Free Software Foundation.
11 #   Fail is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 # This file builds lua. The idea is that the lua subdirectory contains
21 # a vanilla lua distribution and that this files takes chagres of applying
22 # all the required changes before building it (mainly copying the files and
23 # renameing them with a cpp suffix to compile lua as c++, but also changing
24 # the parameters to dlopen in the library loader so throwing from a lua module
25 # works properly)
26 include( CheckFunctionExists )
28 check_function_exists( mkstemp HAVE_MKSTEMP )
30 set( CMAKE_REQUIRED_INCLUDES readline/readline.h )
31 set( CMAKE_REQUIRED_LIBRARIES readline )
32 check_function_exists( readline HAVE_READLINE )
34 if( HAVE_MKSTEMP )
35         add_definitions( -DLUA_USE_MKSTEMP )
36 endif( HAVE_MKSTEMP )
38 if( HAVE_READLINE )
39         add_definitions( -DLUA_USE_READLINE )
40 endif( HAVE_READLINE )
42 if( UNIX )
43         add_definitions( -DLUA_USE_LINUX )
44 endif( UNIX )
46 # We copy all the lua files into the build directory, so we can:
47 #  - rename .c files into .cpp, so lua gets compiled as C++ (and so will use c++ exceptions to handle errors instead of setjmp/longjmp)
48 #  - replace luaconf.h with our own
49 # The benefit is the ability to drop in a new version of lua in the source tree without having to to any change to the files directly.
50 file( GLOB lua_header_files ${PROJECT_SOURCE_DIR}/libs/lua/src/*.h )
51 file( GLOB lua_source_files  ${PROJECT_SOURCE_DIR}/libs/lua/src/*.c )
53 foreach( file ${lua_header_files} )
54         string( REPLACE ${PROJECT_SOURCE_DIR}/libs/lua/src/ "" filename ${file} )
56         configure_file(
57                 ${file}
58                 ${PROJECT_BINARY_DIR}/libs/lua/src/${filename}
59         )
60 endforeach( file )
62 foreach( file ${lua_source_files} )
63         string( REPLACE ${PROJECT_SOURCE_DIR}/libs/lua/src/ "" filename ${file} )
65         configure_file(
66                 ${file}
67                 ${PROJECT_BINARY_DIR}/libs/lua/src/${filename}pp
68         )
69 endforeach( file )
71 # Replace the luaconf file
72 configure_file(
73         ${PROJECT_SOURCE_DIR}/libs/luaconf.h
74         ${PROJECT_BINARY_DIR}/libs/lua/src/luaconf.h
77 # Replace RTLD_NOW with RTLD_GLBOAL | RTLD_NOW in loadlib.c to make
78 # lua friendly to C++ shared objects. Otherwise std::type_info comparisons
79 # fail, and therefore so do dynamic_cast and exception handling.
80 # (cf http://gcc.gnu.org/faq.html#dso)
81 file( READ ${PROJECT_SOURCE_DIR}/libs/lua/src/loadlib.c loadlibsrc )
82 string( REPLACE RTLD_NOW "RTLD_GLOBAL | RTLD_NOW" loadlibsrc "${loadlibsrc}" )
83 file( WRITE ${PROJECT_BINARY_DIR}/libs/lua/src/loadlib.cpp "${loadlibsrc}" )
85 set( lua_lib_files
86         lapi
87         lcode
88         ldebug
89         ldo
90         ldump
91         lfunc
92         lgc
93         llex
94         lmem
95         lobject
96         lopcodes
97         lparser
98         lstate
99         lstring
100         ltable
101         ltm
102         lundump
103         lvm
104         lzio
105         lauxlib
106         lbaselib
107         ldblib
108         liolib
109         lmathlib
110         loslib
111         ltablib
112         lstrlib
113         loadlib
114         linit
117 foreach( file ${lua_lib_files} )
118         #configure_file(
119         #       ${PROJECT_SOURCE_DIR}/libs/lua/src/${file}.c
120         #       ${PROJECT_BINARY_DIR}/libs/lua/src/${file}.cpp
121         #)
122         
123         list( APPEND lua_cpp_files ${PROJECT_BINARY_DIR}/libs/lua/src/${file}.cpp )
124 endforeach( file )
127 include_directories( ${LUA_INCLUDE_DIR} )
129 add_library( fail-lua SHARED ${lua_cpp_files} )
133 install( TARGETS fail-lua DESTINATION lib )
135 configure_file(
136         ${PROJECT_SOURCE_DIR}/libs/lua/src/lua.c
137         ${PROJECT_BINARY_DIR}/libs/lua/src/lua.cpp
140 add_executable( fail-lua-exe ${PROJECT_BINARY_DIR}/libs/lua/src/lua.cpp )
142 set_target_properties( fail-lua-exe PROPERTIES OUTPUT_NAME fail-lua )
145 target_link_libraries( fail-lua-exe fail-lua )
147 if( UNIX )
148   target_link_libraries( fail-lua-exe dl )
149 endif( UNIX )
151 if( HAVE_READLINE )
152         target_link_libraries( fail-lua-exe readline )
153 endif( HAVE_READLINE )
155 install( TARGETS fail-lua-exe DESTINATION bin )
157 subdirs(
158         lqt