I have a lot of libraries in my project, and a LOT of individual applications. A few of the my libraries have dependency libraries, some of them external ones, and I'd like a way for the application CMakeList.txt files to be simpler. I'm hoping to use macros to simplify.
Below is a much reduced test case. For example, in my project, including one of my libraries requires also include_directories, link_directories, and target_link_libraries for ImageMagick, pugixml, jsoncpp, liboauthcpp, etc... And, some of these third party libraries require compiler flags. My project's version of the _LIB() macro below will be much longer...
Question: Is there a way I can have the _LIB() macro below automatically add something to the target_link_libraries that invoke the macro?
I'm not sure how to do that because target_link_libraries argument 1 is the target name, which changes per application.
~/codeTest/CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(codeTest)
macro(_LIB)
include_directories(~/codeTest/lib)
link_directories(~/codeTest/lib)
endmacro()
add_subdirectory(lib)
add_subdirectory(app)
~/codeTest/lib/CMakeLists.txt
include_directories(~/codeTest/lib)
add_library(lib lib.cpp)
~/codeTest/lib/lib.h
#ifndef __LIB__
#define __LIB__
namespace LIB {
unsigned long libFunc(unsigned long inValue);
}
#endif
~/codeTest/lib/lib.cpp
#include <lib.h>
namespace LIB {
unsigned long libFunc(unsigned long inValue) {
return inValue+1;
}
}
~/codeTest/app/CMakeLists.txt
_LIB()
add_executable(app app.cpp)
target_link_libraries(app lib)
~/codeTest/app/app.cpp
#include <lib.h>
using namespace LIB;
int main() {
unsigned long x = 1;
unsigned long y = libFunc(x);
}