0
votes

I have a simple C project structure:

proj/
  src/
  docs/
  build/
  tests/
  lib/

Trying to write a suitable CMake file.

My attempt so far: http://pastebin.com/846ZzUev

CMake Error at CMakeLists.txt:6 (PROJECT_SOURCE_DIR): Unknown CMake command "PROJECT_SOURCE_DIR".

-- Configuring incomplete, errors occurred! See also "/path/to/proj/CMakeFiles/CMakeOutput.log".

*How do I: *

  • Force a custom compiler.
  • Auto-include all library folders with automatic file detection.
  • (PROJECT_ROOT/src and PROJECT_ROOT/lib)
1

1 Answers

2
votes
  1. Unknown CMake command "PROJECT_SOURCE_DIR". - PROJECT_SOURCE_DIR isn't a command, it's a variable. It looks like you're trying to tell CMake where your code lives - the usual way of doing this is simply placing the CMakeLists.txt file in root of the project.

  2. "Force a custom compiler." - This is covered in the FAQ.

  3. "Auto-include all library folders with automatic file detection." - You mean something like described in this answer(more discussion here)? The idiomatic CMake way of doing this would be to explicitly list the targets with their source files.