On 05/27/2010 04:59 PM, Torri, Stephen CIV NSWCDD, W15 wrote:
> I am attempting to build a shared library as a project. In order to explain
> my project I will use a pseudo project with a similar setup. The library is
> called TruckInterface with four directories (Wheels, Engine, Frame and
> Truck). The directories Wheels, Engine and Frame are built as static
> libraries and Truck is a shared library to be installed.
>
> TruckInterface
> |------- Wheels
> |------- Engine
> |------- Frame
> |------- Truck
>
> In the CMakeLists.txt for Wheels, Engine and Frame I have followed the format
> below:
>
> SET ( HEADERS ..list header files )
> SET ( SOURCES ...list source files )
>
> INCLUDE_DIRECTORIES ( ...other directory to look for headers in the
> project... )
>
> add_library ( <name> STATIC ${SOURCES} ${HEADERS} )
In general, there's no need to specify headers in ADD_LIBRARY() or
ADD_EXECUTABLE(). Usually, this does no harm, but dependencies of
source files on headers are figured out by CMake automatically.
An exception would be if the HEADERS trigger further actions.
> In the CMakeLists.txt for Truck I have
>
> SET ( HEADERS ..list header files )
> SET ( SOURCES ...list source files )
>
> INCLUDE_DIRECTORIES ( ...other directory to look for headers in the
> project... )
>
> add_library ( Truck SHARED ${SOURCES} ${HEADERS} )
> link_libraries ( Wheels Engine Frame )
CMake 2.4 documentation states: "LINK_LIBRARIES: Link libraries to all
targets *added later*." Thus, Wheels, Engine and Frame are not linked
to Truck, possibly resulting in... undefined references. Furthermore,
LINK_LIBRARIES() is considered as obsolete, use TARGET_LINK_LIBRARIES()
instead.
> Now my problems that I am coming across, some of which are not cmake's fault:
>
> 1. Undefined references even though the code has been declared for member
> functions
Just for my understanding, "declared for member functions" means the
declaration for export to a DLL, i.e. the dllexport attribute, e.g.?
> 2. Unable to set global compiler flags in the CMakeLists in the
> TruckInterface directory
What have you done so far in this regard? Doesn't setting
CMAKE_C_FLAGS, CMAKE_CXX_FLAGS et al. suit your needs?
> 3. How to select when I want a debug versus a release build.
If using Make for building, set CMAKE_BUILD_TYPE to "debug", "release"
etc.; otherwise, AFAIK, the build type is chosen during the build.
Regards,
Michael
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake