studie
studie

Reputation: 169

CMake find_path is not finding path in simple example

Find_path just does not work for me at all under any circumstances, so I constructed what I thought was the simplest possible test case.

My directory structure for source code contains

E:/Include/fred.h
E:/Src/fizzbuzz/CMakeLists.txt
E:/Src/fizzbuzz/fizzbuzz.cpp

CMakeLists.txt is:

cmake_minimum_required(VERSION 3.12)
project (fizzbuzz)
find_path(
    GSLINCLUDE
    NAMES "fred.h"
    PATHS ../..   E:/
)
message(STATUS "GSLINCLUDE => ${GSLINCLUDE}")
add_executable(fizzbuzz fizzbuzz.cpp stdafx.h)

which gives me the result:

-- GSLINCLUDE => GSLINCLUDE-NOTFOUND
-- Configuring done
-- Generating done
-- Build files have been written to: E:/src/fizzbuzz

Presumably I am doing something simple and obviously wrong in each and every case, but what would work in this simple example with this extremely simple directory structure?

And if CMake is just not expecting such a simple directory structure, what directory structure would make it happy?

Upvotes: 10

Views: 20497

Answers (1)

gordan.sikic
gordan.sikic

Reputation: 1640

in brief, find_path is not recursive, so if you want something to be found in Include subfolder, you have 2 options:

state path file should reside (note E:/Include instead of E:/):

find_path(
    GSLINCLUDE
    NAMES "fred.h"
    PATHS ../..   E:/Include
)

other option is to use PATH_SUFFIXES modifier:

find_path(
    GSLINCLUDE
    NAMES "fred.h"
    PATHS ../..   E:/
    PATH_SUFFIXES Include
)

At the end, here is the complete documentation about find_path

Upvotes: 12

Related Questions