How to work with CMake + Xcode 4 path dependencies?

I have projects structured like this:

Libs/
Apps1/
Apps2/

In each folder is located CMakeLists.txt. I would like to generate a project file for each of the folders, and each one AppsNrefers to Libs. My way to do this is by invoking CMake add_subdirectory(../Libs/Source/LibN), etc.

Now that I do this, CMake says that it add_subdirectoryshould specify a unique absolute path for the binary output folder.

See this post:

Xcode dependencies on different build directories?

Xcode cannot handle dependencies when the assembly output folder is unique to each target. He needs one folder. And CMake does this by default, it simply refuses when the folder is not subdir.

I tried changing and changing the output path after creating the target. This will create objects in the output folder, Xcode will see them, but all links to this target in the CMake script will use a unique path.

Suggested solutions:

  • include project files in App1/Projects/Subdirand duplicate projects in an irrelevant place
  • reorganize my folders to a shared parent folder to avoid this CMake madness, which presents some security issues for me (as some drives are not public)
  • never refer to a target with your CMake name, use a common path name instead. Not sure how to do it right.
  • try to make it fixed on the CMake side somehow
  • go to the wise
+3
source share
1 answer

CMakeLists.txt :

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
PROJECT (ContainerProject)

SET (LIBRARY_OUTPUT_PATH ${ContainerProject_BINARY_DIR}/bin CACHE PATH
  "Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${ContainerProject_BINARY_DIR}/bin CACHE PATH
  "Single output directory for building all executables.")
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)

# for common headers (all project could include them, off topic)
INCLUDE_DIRECTORIES(ContainerProject_SOURCE_DIR/include)

# for add_subdirectory:
# 1) do not use relative paths (just as an addition to absolute path),
# 2) include your stuffs in build order, so your path structure should
#    depend on build order,
# 3) you could use all variables what are already loaded in previous
#    add_subdirectory commands.
#
# - inside here you should make CMakeLists.txt for all libs and for the
# container folders, too.
add_subdirectory(Libs)

# you could use Libs inside Apps, because they have been in this point of
# the script
add_subdirectory(Apps1)
add_subdirectory(Apps2)

Libs CMakeLists.txt:

add_subdirectory(Source)

Source CMakeLists.txt:

add_subdirectory(Lib1)
# Lib2 could depend on Lib1
add_subdirectory(Lib2)

, Apps . ${root}/bin.

lib:

PROJECT(ExampleLib)
INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
)
SET(ExampleLibSrcs
  ...
)
ADD_LIBRARY(ExampleLib SHARED ${ExampleLibSrcs})

( ):

PROJECT(ExampleBin)
INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${ExampleLib_SOURCE_DIR}
)
SET(ExampleBinSrcs
  ...
)
# OSX gui style executable (Finder could use it)
ADD_EXECUTABLE(ExampleBin MACOSX_BUNDLE ${ExampleBinSrcs})
TARGET_LINK_LIBRARIES(ExampleBin
  ExampleLib
)

.

+2

All Articles