<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><a name="_MailEndCompose"><o:p> </o:p></a></p>
<p class="MsoNormal"><span style="mso-bookmark:_MailEndCompose"><o:p> </o:p></span></p>
<span style="mso-bookmark:_MailEndCompose"></span>
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal">I’m posting this after getting no useful reply in StackOverflow:
<a href="https://stackoverflow.com/questions/50198141/cmake-custom-target-doesnt-build">
https://stackoverflow.com/questions/50198141/cmake-custom-target-doesnt-build</a>.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">Using CMake 2.8.8, I'm building two targets using:<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">add_library(tgt1 SHARED a.cpp)<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">add_library(tgt2 SHARED b.cpp)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">After both are built, I need to run a post build step that depends on both targets. I tried many combinations of the following but with no success:<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">add_custom_target(final_tgt DEPENDS tgt1 tgt2)<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">add_custom_command(TARGET final_tgt POST_BUILD COMMAND <command>
 ARGS <args>)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">The final target would simply not build, even though its build.make contains the custom command.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">Tried to use ALL for the custom target, however make attempts to build it first while missing the first targets.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">And I can't use an add_library or add_executable for the final target, since they require specifying source files.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">What is the correct way to do it?<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">===================================<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">Edit: below is a minimal verifiable source code. What it attempts to do is to compile code (for Mac) in two architectures and as a post-build to create a universal binary using lipo:<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">cmake_minimum_required(VERSION 2.8)<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">set(icpc_req_path "/usr/local/bin/icpc-16.0.146")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">set(CMAKE_CXX_COMPILER "${icpc_req_path}")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">project("CMakeTest")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">set(SOURCE_FILES a.cpp)<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">set (TARGET_NAME "TGT")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">set(TARGETS "")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">set(ARCHITECTURES i386 x86_64)<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">foreach(ar ${ARCHITECTURES})<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">    set(CMAKE_CXX_FLAGS_RELEASE "")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">    set(CMAKE_CXX_FLAGS_DEBUG "")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">    set(CMAKE_CXX_FLAGS "")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">    add_library(TGT_${ar} SHARED ${SOURCE_FILES})<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">    set_target_properties(${TARGET_NAME}_${ar} PROPERTIES COMPILE_FLAGS
 "-arch ${ar} -xSSE3")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">    set_target_properties(${TARGET_NAME}_${ar} PROPERTIES LINK_FLAGS
 "-arch ${ar}")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">    set(TARGETS "${TARGETS};lib${TARGET_NAME}_${ar}.dylib")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">endforeach(ar)<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">message("Targets: ${TARGETS}")<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">add_custom_target(${TARGET_NAME} DEPENDS ${TARGETS})<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND
 "lipo" ARGS "-create" ${TARGETS} "-output" "${TARGET_NAME}.dylib")<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt;background:white;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">And the contents of a.cpp is:<o:p></o:p></span></p>
<p class="MsoNormal" style="background:#EFF0F1;vertical-align:baseline"><span style="font-size:10.0pt;font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">int main(){}</span><span style="font-size:10.0pt;font-family:Consolas;color:#242729"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Gil.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>