Hi,
I'm posting this after getting no useful reply in StackOverflow: 
https://stackoverflow.com/questions/50198141/cmake-custom-target-doesnt-build.

Using CMake 2.8.8, I'm building two targets using:
add_library(tgt1 SHARED a.cpp)
add_library(tgt2 SHARED b.cpp)
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:
add_custom_target(final_tgt DEPENDS tgt1 tgt2)
add_custom_command(TARGET final_tgt POST_BUILD COMMAND <command> ARGS <args>)
The final target would simply not build, even though its build.make contains 
the custom command.
Tried to use ALL for the custom target, however make attempts to build it first 
while missing the first targets.
And I can't use an add_library or add_executable for the final target, since 
they require specifying source files.
What is the correct way to do it?
===================================
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:
cmake_minimum_required(VERSION 2.8)
set(icpc_req_path "/usr/local/bin/icpc-16.0.146")

set(CMAKE_CXX_COMPILER "${icpc_req_path}")

project("CMakeTest")
set(SOURCE_FILES a.cpp)

set (TARGET_NAME "TGT")
set(TARGETS "")
set(ARCHITECTURES i386 x86_64)

foreach(ar ${ARCHITECTURES})
    set(CMAKE_CXX_FLAGS_RELEASE "")
    set(CMAKE_CXX_FLAGS_DEBUG "")
    set(CMAKE_CXX_FLAGS "")

    add_library(TGT_${ar} SHARED ${SOURCE_FILES})
    set_target_properties(${TARGET_NAME}_${ar} PROPERTIES COMPILE_FLAGS "-arch 
${ar} -xSSE3")
    set_target_properties(${TARGET_NAME}_${ar} PROPERTIES LINK_FLAGS "-arch 
${ar}")
    set(TARGETS "${TARGETS};lib${TARGET_NAME}_${ar}.dylib")
endforeach(ar)

message("Targets: ${TARGETS}")
add_custom_target(${TARGET_NAME} DEPENDS ${TARGETS})
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND "lipo" ARGS 
"-create" ${TARGETS} "-output" "${TARGET_NAME}.dylib")

And the contents of a.cpp is:
int main(){}

Thanks,
Gil.

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to