2008-03-25 18:27:18 +03:00
|
|
|
cmake_minimum_required (VERSION 2.6)
|
2012-08-13 21:47:32 +04:00
|
|
|
project (ExternalOBJ)
|
2005-02-04 21:58:11 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(APPLE)
|
2006-03-24 17:15:05 +03:00
|
|
|
# set _CMAKE_OSX_MACHINE to umame -m
|
2012-08-13 21:47:32 +04:00
|
|
|
exec_program(uname ARGS -m OUTPUT_VARIABLE _CMAKE_OSX_MACHINE)
|
2006-03-24 17:15:05 +03:00
|
|
|
# check for Power PC and change to ppc
|
2012-08-13 21:47:32 +04:00
|
|
|
if("${_CMAKE_OSX_MACHINE}" MATCHES "Power")
|
|
|
|
set(_CMAKE_OSX_MACHINE ppc)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_OSX_ARCHITECTURES ${_CMAKE_OSX_MACHINE})
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2006-03-24 17:15:05 +03:00
|
|
|
|
2005-02-04 21:58:11 +03:00
|
|
|
# Build the external object file.
|
2012-08-13 21:47:32 +04:00
|
|
|
try_compile(EXTERNAL_OBJECT_BUILT
|
2005-02-04 21:58:11 +03:00
|
|
|
${ExternalOBJ_BINARY_DIR}/Object
|
|
|
|
${ExternalOBJ_SOURCE_DIR}/Object
|
|
|
|
Object
|
|
|
|
external
|
|
|
|
OUTPUT_VARIABLE OUTPUT
|
|
|
|
)
|
2012-08-13 21:47:32 +04:00
|
|
|
if(EXTERNAL_OBJECT_BUILT)
|
|
|
|
message(
|
2007-12-29 07:07:26 +03:00
|
|
|
"Building external_object.cxx succeeded with the following output:\n"
|
2005-02-04 21:58:11 +03:00
|
|
|
"[${OUTPUT}]"
|
|
|
|
)
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
message(FATAL_ERROR
|
2007-12-29 07:07:26 +03:00
|
|
|
"Building external_object.cxx failed with the following output:\n"
|
2005-02-04 21:58:11 +03:00
|
|
|
"[${OUTPUT}]"
|
|
|
|
)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2005-02-04 21:58:11 +03:00
|
|
|
|
|
|
|
# Find the external object file.
|
2012-08-13 21:47:32 +04:00
|
|
|
set(DIR ${ExternalOBJ_BINARY_DIR}/Object)
|
|
|
|
file(GLOB_RECURSE EXTERNAL_OBJECT
|
2007-12-29 07:07:26 +03:00
|
|
|
"${DIR}/external_object*${CMAKE_CXX_OUTPUT_EXTENSION}")
|
2012-08-13 21:47:32 +04:00
|
|
|
if(EXTERNAL_OBJECT)
|
|
|
|
list (GET EXTERNAL_OBJECT 0 EXTERNAL_OBJECT)
|
|
|
|
message("Found \"${EXTERNAL_OBJECT}\".")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
message(FATAL_ERROR "Could not find external object.")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2005-02-04 21:58:11 +03:00
|
|
|
|
2005-11-17 21:49:10 +03:00
|
|
|
# Test creation of external objects by custom commands.
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CUSTOM_OBJECT
|
2005-11-17 21:49:10 +03:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/custom_object${CMAKE_C_OUTPUT_EXTENSION})
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_command(
|
2005-11-17 21:49:10 +03:00
|
|
|
OUTPUT ${CUSTOM_OBJECT}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${EXTERNAL_OBJECT} ${CUSTOM_OBJECT}
|
|
|
|
DEPENDS ${EXTERNAL_OBJECT}
|
|
|
|
)
|
|
|
|
|
2011-04-02 00:28:41 +04:00
|
|
|
message("${EXTERNAL_OBJECT}")
|
2005-02-04 21:58:11 +03:00
|
|
|
# Build an executable using the external object file.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(ExternalOBJ executable.cxx ${CUSTOM_OBJECT})
|
2011-04-02 00:28:41 +04:00
|
|
|
# A bug showed up in VS2010 where an object file that was
|
|
|
|
# part of a custom commad output worked, but ones that were
|
|
|
|
# not didn't work. So, repeat the executable using the object
|
|
|
|
# directly and not from the output of the copy.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(ExternalOBJ2 executable.cxx ${EXTERNAL_OBJECT})
|
2012-03-20 01:14:52 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_subdirectory(Sub)
|