<p>Tag with cmake.</p>
<p>在 2012-11-5 上午10:39,"lzprgmr" <<a href="mailto:baiyanhuang@gmail.com">baiyanhuang@gmail.com</a>>写道:<br>
><br>
> Hi, All<br>
><br>
> After going through the cmake examples, I decide trying build lua with<br>
> cmake to get a better understanding, and got some questions.<br>
><br>
> First, the lua source code are placed in one flat directory (src/) and<br>
> will generate 3 targets: a static lib, a lua interpreter and a lua<br>
> compiler. my cmake script looks like:<br>
><br>
> cmake_minimum_required (VERSION 2.6)<br>
> project (lua) # project here actually means solution in premake<br>
><br>
> # 1. lua static library<br>
> if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")<br>
> add_definitions( -D_CRT_SECURE_NO_WARNINGS )<br>
> endif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")<br>
><br>
> # how to rename library name?<br>
> add_library (lualib STATIC lapi.c lcode.c lctype.c ldebug.c ldo.c<br>
> ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c<br>
> lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c<br>
> lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c lmathlib.c loslib.c<br>
> lstrlib.c ltablib.c loadlib.c linit.c)<br>
><br>
><br>
> # 2. lua interpreter<br>
> link_directories (${LUA_BINARY_DIR})<br>
> add_executable (lua lua.c)<br>
> target_link_libraries (lua lualib)<br>
> if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")<br>
> target_link_libraries( lua m )<br>
> endif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")<br>
><br>
> # 3. lua compiler<br>
> link_directories (${LUA_BINARY_DIR})<br>
> add_executable (luac luac.c)<br>
> target_link_libraries (luac lualib)<br>
> if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")<br>
> target_link_libraries( luac m )<br>
> endif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")<br>
><br>
> But it seems a litte bit problematic to me, questions are as below:<br>
><br>
> * It seems to me cmake are best work with source code with consistent<br>
> structure of its targets. in my case, I have to define all my targets<br>
> in one CMakeLists.txt file, the problem I can see is the property I<br>
> set for 1st target (one example is the macro definition:<br>
> -D_CRT_SECURE_NO_WARNINGS ) will also applies to the 2nd, which is not<br>
> expected. is there a way to avoid this?<br>
><br>
> * Here the final target name for the lua library and lua interpreter<br>
> are liblua.a and lua (in linux), because here I can't name both<br>
> library and executable as "lua", I would hope there is a way for me to<br>
> rename the target, like:<br>
> add_library(lualib targetname=lua)<br>
> and then I can depends on it using the project name:<br>
> target_link_libraries(lua lualib)<br>
> Is it possible to achieve this in cmake?<br>
><br>
> * I guard platform specific setting using if(${CMAKE_SYSTEM_NAME}<br>
> STREQUAL "Linux"), which seems quite tedious to me, is there a neat<br>
> way to do so?<br>
><br>
> Thanks.<br>
</p>