CMake to mimic Google Build language

Google use a description language for build and dependency management. That is very convenient, in order to use some libraries, you just need to include some headers in your C++, and add that libraries path to 'deps' list.

I'm using CMake for personal tiny projects. One CMake feature that annoys me a lot is no target namespaces. We can not define the same target in different directories. So I thought, we can define some Google BUILD like functions for CMake and make every target dependent on the it's directory. In my personal tiny projects, I'm using weizi as root of source directory, and in every sub directory, we can refer targets in current directory directly and targets in other directory with full path.

CC_BINARY(diff_spell_check
  SRCS diff_spell_check.cc
  LIBS /options_parser/options_parser)
CC_BINARY(csv2sqlite 
  SRCS csv2sqlite.cc
  LIBS /options_parser/options_parser
       /third_party/sqlite)
CC_TEST(csv_split_test 
  SRCS csv_split_test.cc
  LIBS /test/test_lite_main)

We can not use '/' in target names directly, one choice is using '.' to join directories.

No comments: