Skip to content

Commit f4bd932

Browse files
committed
Implement searching for tool installations.
1 parent bf50036 commit f4bd932

File tree

2 files changed

+126
-7
lines changed

2 files changed

+126
-7
lines changed

Diff for: Modules/MicrochipPathSearch.cmake

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#=============================================================================
2+
# Copyright 2016 Sam Hanes
3+
#
4+
# Distributed under the OSI-approved BSD License (the "License");
5+
# see accompanying file COPYING.txt for details.
6+
#
7+
# This software is distributed WITHOUT ANY WARRANTY; without even the
8+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
# See the License for more information.
10+
#=============================================================================
11+
# (To distribute this file outside of CMake-Microchip,
12+
# substitute the full License text for the above reference.)
13+
14+
function(MICROCHIP_PATH_SEARCH outvar target)
15+
set(options)
16+
list(APPEND oneValueArgs "CACHE")
17+
set(multiValueArgs BAD_VERSIONS)
18+
cmake_parse_arguments(SEARCH
19+
"${options}" "${oneValueArgs}" "${multiValueArgs}"
20+
${ARGN}
21+
)
22+
23+
if(SEARCH_CACHE)
24+
set(${outvar} "" CACHE PATH "${SEARCH_CACHE}")
25+
if(${outvar})
26+
if(EXISTS "${${outvar}}")
27+
set(${outvar} "${${outvar}}" PARENT_SCOPE)
28+
else()
29+
message(FATAL_ERROR
30+
"given path '${${outvar}}' does not exist"
31+
" in ${outvar} (${SEARCH_CACHE})"
32+
)
33+
set(${outvar} "${outvar}-NOTFOUND" PARENT_SCOPE)
34+
endif()
35+
return()
36+
endif()
37+
endif()
38+
39+
set(MICROCHIP_SEARCH_PATH ""
40+
CACHE STRING "the search path for Microchip tool installations"
41+
)
42+
43+
if(CMAKE_HOST_SYSTEM MATCHES "Linux")
44+
list(APPEND MICROCHIP_SEARCH_PATH /opt/microchip)
45+
elseif(CMAKE_HOST_SYSTEM MATCHES "Windows")
46+
list(APPEND MICROCHIP_SEARCH_PATH
47+
"C:/Program Files/Microchip"
48+
"C:/Program Files (x86)/Microchip"
49+
)
50+
endif()
51+
52+
set(candidate_paths)
53+
foreach(path ${MICROCHIP_SEARCH_PATH})
54+
if(IS_DIRECTORY "${path}/${target}")
55+
list(APPEND candidate_paths "${path}/${target}")
56+
endif()
57+
endforeach()
58+
59+
set(best_good_path)
60+
set(best_good_version)
61+
set(best_bad_path)
62+
set(best_bad_version)
63+
64+
set(msg "\nSearching for Microchip tool '${target}' (${outvar}):")
65+
66+
foreach(path ${candidate_paths})
67+
file(GLOB versions RELATIVE "${path}" "${path}/v*")
68+
foreach(version_path ${versions})
69+
string(REGEX REPLACE "^v" "" version "${version_path}")
70+
71+
set(type good)
72+
if(${version} IN_LIST SEARCH_BAD_VERSIONS)
73+
set(type bad)
74+
endif()
75+
76+
string(APPEND msg
77+
"\n ${type} ${version} = ${path}/${version_path}"
78+
)
79+
80+
if(NOT best_${type}_version
81+
OR version VERSION_GREATER best_${type}_version)
82+
set(best_${type}_version "${version}")
83+
set(best_${type}_path "${path}/${version_path}")
84+
endif()
85+
endforeach()
86+
endforeach()
87+
88+
if(best_good_path)
89+
set(result "${best_good_path}")
90+
elseif(best_bad_path)
91+
set(result "${best_bad_path}")
92+
93+
message(WARNING
94+
"Version ${best_bad_version} of ${target} is known"
95+
" to be problematic. If you encounter issues, set"
96+
" ${outvar} to a different version."
97+
)
98+
else()
99+
set(result "${outvar}-NOTFOUND")
100+
endif()
101+
102+
string(APPEND msg
103+
"\n Best good version: ${best_good_version}"
104+
"\n Best bad version: ${best_bad_version}"
105+
"\n Chose: ${result}"
106+
)
107+
file(APPEND
108+
"${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeOutput.log"
109+
"${msg}\n\n"
110+
)
111+
112+
if(SEARCH_CACHE)
113+
set(${outvar} "${result}"
114+
CACHE PATH "${SEARCH_CACHE}" FORCE
115+
)
116+
endif()
117+
set(${outvar} "${result}" PARENT_SCOPE)
118+
endfunction()

Diff for: Modules/Platform/MicrochipMCU-C-XC16.cmake

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
# this module is called by `Platform/MicrochipMCU-C`
1515
# to provide information specific to the XC16 compiler
1616

17-
18-
# set the (default) path to XC16
19-
set(MICROCHIP_XC16_PATH "/opt/microchip/xc16/v1.25"
20-
CACHE PATH "the path at which Microchip XC16 is installed"
17+
include(MicrochipPathSearch)
18+
MICROCHIP_PATH_SEARCH(MICROCHIP_XC16_PATH xc16
19+
CACHE "the path to a Microchip XC16 installation"
20+
BAD_VERSIONS 1.26
2121
)
2222

23-
# validate the XC16 path
24-
if(NOT EXISTS ${MICROCHIP_XC16_PATH})
23+
if(NOT MICROCHIP_XC16_PATH)
2524
message(FATAL_ERROR
26-
"XC16 path '${XC16_PATH}' does not exist"
25+
"No Microchip XC16 compiler was found. Please provide the path"
26+
" to an XC16 installation on the command line, for example:\n"
27+
"cmake -DMICROCHIP_XC16_PATH=/opt/microchip/xc16/v1.25 ."
2728
)
2829
endif()
2930

0 commit comments

Comments
 (0)