creating a standalone STATIC/SHARED top level target from other targets

cmake_minimum_required(VERSION 3.10.2)

hey, I was wondering what is the best way to achieve the following goals (given the folder structure below):

  • create a shared/static lib from each sub project, sdk::a and sdk::b. Ideally not generated unless used explicitly.
  • create tests executables for each sub project that was generated.
  • optionally create a top level standalone target sdk::sdk (static/shared).
  • if sdk::sdk is created aggregate the test cases into a single sdk::sdk test.

I’ve considered adding addition object targets (I.e sdk::a_obj sdk::a_test_obj ) or aggregating the sources/includes in a list, which is better? are the any better alternatives?

is there a way to conditionally generate the sub projects and their tests without using flags everywhere? add_sub_directory("${path}" EXCLUDE_FROM_ALL) no longer holds because the file is used by sdk::sdk.

is there a way to configure the targets to be SHARED/STATIC/OBJECT sperately from the top level using cmake builtin functions? could it be done using the alias?

sdk/
├── cmake/
├── externals/
├── sdk/
│   ├── a/
│   │   ├── include/
│   │   │   └── sdk/
│   │   │       └── a.hpp
│   │   ├── src/
│   │   │   └── a.cpp
│   │   ├── tests/
│   │   │   └── test_a.cpp
│   │   └── CMakeLists.txt
│   ├── b/
│   │   ├── include/
│   │   │   └── sdk/
│   │   │       └── b.hpp
│   │   ├── src/
│   │   │   └── b.cpp
│   │   ├── tests/
│   │   │   └── test_b.cpp
│   │   └── CMakeLists.txt
│   └── CMakeLists.txt
└── CMakeLists.txt