Given the simplest working example, I can think of: 2 classes, a and b , where a depends on b ..
hijras
#ifndef A_H #define A_H class aclass { public: int method(int x, int y); }; #endif
a.cpp
#include "ah" #include "bh" int aclass::method(int x, int y) { bclass b; return x * b.method(x,y); }
bh
#ifndef B_H #define B_H class bclass { public: int method(int x, int y); }; #endif
b.cpp
#include "bh" int bclass::method(int x, int y) { return x+y; }
main.cpp
#include "ah" #include <iostream> int main() { aclass a; std::cout << a.method(3,4) << std::endl; return 0; }
You can compile them into separate static libraries, and then combine the static libraries with a custom target.
cmake_minimum_required(VERSION 2.8.7) add_library(b b.cpp bh) add_library(a a.cpp ah) add_executable(main main.cpp) set(C_LIB ${CMAKE_BINARY_DIR}/libcombi.a) add_custom_target(combined COMMAND ar -x $<TARGET_FILE:a> COMMAND ar -x $<TARGET_FILE:b> COMMAND ar -qcs ${C_LIB} *.o WORKING_DIRECTORY ${CMAKE_BINARY_DIR} DEPENDS ab ) add_library(c STATIC IMPORTED GLOBAL) add_dependencies(c combined) set_target_properties(c PROPERTIES IMPORTED_LOCATION ${C_LIB} ) target_link_libraries(main c)
It also works great using the libtool version for the custom Apple libtool target.,.
add_custom_target(combined COMMAND libtool -static -o ${C_LIB} $<TARGET_FILE:a> $<TARGET_FILE:b> WORKING_DIRECTORY ${CMAKE_BINARY_DIR} DEPENDS ab )
Still seams, as if there should be a tidier way ..
source share