cmake - Test whether a CMakeLists.txt is used as a subdirectory -


i want write cmakelists can used not sub-cmakelists both standalone. example, in following setup

a ├── b │   └── cmakelists.txt └── cmakelists.txt 

with

$ cat a/cmakelists.txt add_subdirectory(b) 

however, i'd make a/b/cmakelists.txt standalone cmake file can used directly cmake. in particular, a/b/cmakelists.txt needs perform conditional initialization depending on how used. this:

$ cat a/b/cmakelists.txt if_included # dummy    do_init() endif # else 

so, i'm wondering

  1. is people do?
  2. is there predicate aforementioned if_include (again, dummy)?

i've seen such setup few times, it's people do. common way phrase such test this:

if(cmake_source_dir strequal cmake_current_source_dir) 

(or same binary directories).

cmake_source_dir directory containing toplevel cmakelists.txt (the 1 on cmake invoked). cmake_current_source_dir directory containing cmakelists.txt being processed. if same, it's guaranteed current cmakelist top-level one.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -