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