[CMake] Difference between CMake generated Xcode project and manually created 'bsd c library' project
Michael Norman
mwnorman at gmail.com
Mon Aug 12 09:33:27 EDT 2013
I have a project where the output is a static library. The directory
structure is as follows:
myproj
| CMakeLists.txt
|- cmake_macros
| find_include_dirs.cmake
|- libs
|--- Mac
|----- lib
| libcrypto.a
| ...
|--- win
| ...
|
|- src
|--- component1
| CMakeLists.txt
| some_file.c
| ...
|----- include
| CMakeLists.txt
| some_file.h
| ...
|--- component2
| ...
Each component's cmake file describes the sources and headers for that
component:
project(component1)
set(component1_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/some_file.c
${CMAKE_CURRENT_SOURCE_DIR}/some_other_file.c
)
set(component1_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/some_file.h
${CMAKE_CURRENT_SOURCE_DIR}/include/some_other_file.h
)
add_library(component1 OBJECT ${component1_SOURCES} ${component1_HEADERS})
The top-level cmake file includes each sub-component and builds the
required library:
cmake_minimum_required (VERSION 2.8)
include(cmake_macros/find_include_dirs.cmake)
project (myProject C)
# find all include directories
find_include_dirs(INCLUDE_DIRS)
include_directories(${INCLUDE_DIRS})
# add subdirectories
add_subdirectory(src/component1)
add_subdirectory(src/component2)
...
# platform-specific compiler flags
if (APPLE)
set(ENV{CC} clang)
set(CMAKE_C_FLAGS "-std=gnu99" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all-symbols")
...
endif (APPLE)
add_library(myLib STATIC
$<TARGET_OBJECTS:component1>
$<TARGET_OBJECTS:component2>
...
)
When run without a generator, the command-line compilation works, producing
myLib.a; however, when I generate an Xcode project, I get multiple .a
files, one-per component and no target that links everything together into
a single library.
Any help would be greatly appreciated,
---
Mike Norman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130812/5a3c1bb1/attachment.htm>
More information about the CMake
mailing list