On 11/4/12, lzprgmr <[email protected]> wrote: > Hi, All > > After going through the cmake examples, I decide trying build lua with > cmake to get a better understanding, and got some questions. >
Multiple people have written CMake descriptions to build Lua. I posted my own here awhile back: http://playcontrol.net/ewing/jibberjabber/git_superproject_and_submod.html > * It seems to me cmake are best work with source code with consistent > structure of its targets. in my case, I have to define all my targets > in one CMakeLists.txt file, the problem I can see is the property I > set for 1st target (one example is the macro definition: > -D_CRT_SECURE_NO_WARNINGS ) will also applies to the 2nd, which is not > expected. is there a way to avoid this? set_target_properties lets you specify attributes on a target basis so it doesn't need to be global. SET_TARGET_PROPERTIES(lua_library_static PROPERTIES COMPILE_FLAGS "${LUA_C_FLAGS}") > * Here the final target name for the lua library and lua interpreter > are liblua.a and lua (in linux), because here I can't name both > library and executable as "lua", I would hope there is a way for me to > rename the target, like: > add_library(lualib targetname=lua) > and then I can depends on it using the project name: > target_link_libraries(lua lualib) > Is it possible to achieve this in cmake? Yes it is. This is in my example: ADD_EXECUTABLE(lua_executable ${Lua_SOURCE_DIR}/src/lua.c) TARGET_LINK_LIBRARIES(lua_executable lua_library_static ${LUA_LINKER_FLAGS}) # Makes the executable name "lua" SET_TARGET_PROPERTIES(lua_executable PROPERTIES OUTPUT_NAME "lua") > > * I guard platform specific setting using if(${CMAKE_SYSTEM_NAME} > STREQUAL "Linux"), which seems quite tedious to me, is there a neat > way to do so? There are some built in ones like: IF(APPLE) ELSEIF(UNIX) ELSEIF(WIN32) ENDIF() Still tedious, but sometimes necessary. But be careful what you pick vs. what you actually mean. For example, do you really mean "Linux" or do you mean UNIX? (Also a corner case is that APPLE is also UNIX and using Cygwin on Windows might also give you UNIX.) -Eric -- Beginning iPhone Games Development http://playcontrol.net/iphonegamebook/ -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
