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
--
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:
http://www.cmake.org/mailman/listinfo/cmake