Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: Get root project name

Tags:

c

cmake

project

Suppose I have following C project structure:

├── CMakeLists.txt
├── include
│   ├── header.h
├── README.md 
├── src
│   └── src.c
└── test
    ├── CMakeLists.txt
    └── test.c

The CMakeLists.txt in the root directory contains a project called cproj

PROJECT(cproj C)

Also in test/CMakeLists.txt, I have another project

PROJECT(test C)

The question is how can I assess the project name cproj in the CMakeLists.txt in test directory?

like image 717
tjysdsg Avatar asked Apr 10 '26 09:04

tjysdsg


1 Answers

If I gather your use case correctly, you should probably do as follows:

  1. test is quite likely not a standalone sub-project. It should not have a project directive. If you remove it, it will now be under the cproj project.

  2. Now you looking for the project name you've set in the root, it should be available via the CMAKE_PROJECT_NAME variable.

like image 120
StoryTeller - Unslander Monica Avatar answered Apr 13 '26 04:04

StoryTeller - Unslander Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!