-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf_cmake.py
36 lines (31 loc) · 1.18 KB
/
cf_cmake.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#=============================================================================
#
# Copyright (c) Kitware, Inc.
# All rights reserved.
# See LICENSE.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the above copyright notice for more information.
#
#=============================================================================
import os.path
#given a path find the git root directory for that path
def get_project_root(path):
def words(fileobj):
for line in fileobj:
for word in line.split('='):
yield word
#see if we have a CMakeCache.txt file in our current location
search_terms = ("CMAKE_HOME_DIRECTORY:INTERNAL")
if os.path.exists(path):
cmake_cache_file = os.path.join(path,"CMakeCache.txt")
if os.path.isfile(cmake_cache_file):
with open(cmake_cache_file) as cmake_cache:
word_gen = words(cmake_cache)
for item in word_gen:
if item in search_terms:
#get the path and strip trailing and leading whitespace!
path = word_gen.next().strip()
return path
return None