How to specify gcm.cache location using g++ & CMake

Viewed 468

I am currently working on a project which requires C++20 (g++ v11) features and CMake. The project tree is similar to the following one:

- Top level
  - src
     - IO
       - IO.cpp
       - CMakeLists.txt
  - main.cpp
  - CMakeLists.txt

CMake compiles IO module without any problem but It generates gcm.cache folder in a following way:

- build
   - Some other CMake files and folders
   - bin
   - lib 
   - src
     - IO
       - gcm.cache
          - IO.gcm

Therefore, g++ can not find gcm.cache folder and gives me this error:

IO: error: failed to read compiled module: No such file or directory
IO: note: compiled module file is 'gcm.cache/IO.gcm'
IO: note: imports must be built before being imported
IO: fatal error: returning to the gate for a mechanical issue

I would be grateful if anyone tell me that there is a way to specify gcm.cache locations using CMake or force CMake to search gcm files recursively or tell it to create a top level gcm.cache and store everything inside of it. I can not find any answer on anywhere since C++20 documentations are terrible. Thanks in advance...

1 Answers

I have experienced the exact same issue, and without actually discovering a solution have found a workaround. Complete code found here.

In short, I create a symbolic link such that subprojects are all using the gcm.cache/ directory located in the root directory of the project. Create a symlink like so:

ln -fs ../gcm.cache gcm.cache

This is the directory tree of the project:

.
├── engine
│   ├── core
│   │   └── types.cpp
│   ├── engine.cpp
│   ├── gcm.cache -> ../gcm.cache
│   ├── Makefile
│   └── memory
├── gcm.cache
├── init.sh
├── Makefile
└── testgame
    ├── gamelib.cpp
    ├── gcm.cache -> ../gcm.cache
    ├── Makefile
    └── test.cpp

So when gcc builds the engine and testgame projects it actually uses the gcm.cache/ from the root directory. Until something better comes along this is my go-to method.

Related