8000 Support Xcode by not using CMake object libraries. · lineCode/docopt.cpp@de8fd43 · GitHub
[go: up one dir, main page]

Skip to content

Commit de8fd43

Browse files
committed
Support Xcode by not using CMake object libraries.
CMake allows specifying an object file as a source file for a library, but Xcode does not allow creating a library whose source files are *only* object files; there needs to be at least one real source file. This commit gets around this issue by not using object library targets with Xcode.
1 parent 0237c9a commit de8fd43

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ set(docopt_HEADERS
3939
#============================================================================
4040
# Compile targets
4141
#============================================================================
42-
add_library(docopt_o OBJECT ${docopt_SOURCES} ${docopt_HEADERS})
43-
set_target_properties(docopt_o PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
44-
45-
add_library(docopt SHARED $<TARGET_OBJECTS:docopt_o>)
46-
add_library(docopt_s STATIC $<TARGET_OBJECTS:docopt_o>)
42+
if(XCODE)
43+
# Xcode does not support libraries with only object files as sources.
44+
# See https://cmake.org/cmake/help/v3.0/command/add_library.html?highlight=add_library
45+
add_library(docopt SHARED ${docopt_SOURCES} ${docopt_HEADERS})
46+
add_library(docopt_s STATIC ${docopt_SOURCES} ${docopt_HEADERS})
47+
else()
48+
# If not using Xcode, we will create an intermediate object target to avoid
49+
# compiling the source code twice.
50+
add_library(docopt_o OBJECT ${docopt_SOURCES} ${docopt_HEADERS})
51+
set_target_properties(docopt_o PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
52+
53+
add_library(docopt SHARED $<TARGET_OBJECTS:docopt_o>)
54+
add_library(docopt_s STATIC $<TARGET_OBJECTS:docopt_o>)
55+
endif()
4756

4857
target_include_directories(docopt PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)
4958
target_include_directories(docopt_s PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/docopt>)

0 commit comments

Comments
 (0)
0