@@ -27,19 +27,64 @@ if(NOT MICROCHIP_XC8_PATH)
2727 )
2828endif ()
2929
30-
3130set (CMAKE_FIND_ROOT_PATH "${MICROCHIP_XC8_PATH} " )
3231
33- # skip compiler search and just use XC8
34- find_program (CMAKE_C_COMPILER "xc8"
35- PATHS "${MICROCHIP_XC8_PATH} "
36- PATH_SUFFIXES "bin"
32+
33+ if (NOT MICROCHIP_XC8_CLI)
34+ set (MICROCHIP_XC8_CLI "xc8-cc" )
35+ set (_xc8_cli_default TRUE CACHE INTERNAL "" FORCE)
36+ endif ()
37+ set (MICROCHIP_XC8_CLI "${MICROCHIP_XC8_CLI} "
38+ CACHE STRING "the XC8 CLI driver to use ('xc8-cc' or 'xc8')"
3739)
3840
41+
42+ if (MICROCHIP_XC8_CLI STREQUAL "xc8-cc" )
43+ find_program (CMAKE_C_COMPILER "xc8-cc"
44+ PATHS "${MICROCHIP_XC8_PATH} "
45+ PATH_SUFFIXES "bin"
46+ )
47+ set (_xc8_version_flag "--version" )
48+ set (CMAKE_C_COMPILER_ID "XC8CC" )
49+ elseif (MICROCHIP_XC8_CLI STREQUAL "xc8" )
50+ find_program (CMAKE_C_COMPILER "xc8"
51+ PATHS "${MICROCHIP_XC8_PATH} "
52+ PATH_SUFFIXES "bin"
53+ )
54+ set (_xc8_version_flag "--ver" )
55+ set (CMAKE_C_COMPILER_ID "XC8" )
56+ else ()
57+ message (FATAL_ERROR
58+ "Invalid choice '${MICROCHIP_XC8_CLI} ' for MICROCHIP_XC8_CLI."
59+ " Please choose either 'xc8-cc' (recommended) or 'xc8'."
60+ " See docs/xc8.md in your cmake-microchip installation for"
61+ " details on this option."
62+ )
63+ endif ()
64+
65+
3966if (NOT CMAKE_C_COMPILER)
67+ if (_xc8_cli_default)
68+ message (WARNING
69+ "The XC8 command-line driver was not explicitly selected,"
70+ " so the newer 'xc8-cc' driver is being used. This requires"
71+ " XC8 version 2.00 or newer. If you want to use older versions"
72+ " of XC8, or if you want to use the legacy 'xc8' driver in XC8"
73+ " 2.00 or newer, add this line to your CMakeLists.txt before"
74+ " the 'project' command:\n "
75+ " set(MICROCHIP_XC8_CLI xc8)\n "
76+ "To suppress this message when XC8 is not found but continue"
77+ " using the newer 'xc8-cc' driver, add this line to your"
78+ " CMakeLists.txt before the 'project' command:\n "
79+ " set(MICROCHIP_XC8_CLI xc8-cc)\n "
80+ "For more information on selecting a command-line driver"
81+ " see docs/xc8.md in your cmake-microchip installation."
82+ )
83+ endif ()
84+
4085 message (FATAL_ERROR
41- "The XC8 compiler executable was not found, but what looks "
42- " like an XC8 installation was found at:\n "
86+ "The XC8 compiler executable ${MICROCHIP_XC8_CLI} was not found,"
87+ " but what looks like an XC8 installation was found at:\n "
4388 " ${MICROCHIP_XC8_PATH} \n "
4489 "Please provide the path to a working XC8 installation on the"
4590 " command line, for example:\n "
@@ -49,28 +94,27 @@ endif()
4994
5095# skip compiler ID since XC8 isn't supported by CMake's test file
5196set (CMAKE_C_COMPILER_ID_RUN 1)
52- set (CMAKE_C_COMPILER_ID "XC8" )
5397
5498# call the compiler to check its version
5599function (_xc8_get_version)
56100 execute_process (
57- COMMAND "${CMAKE_C_COMPILER} " "--ver "
101+ COMMAND "${CMAKE_C_COMPILER} " "${_xc8_version_flag} "
58102 OUTPUT_VARIABLE output
59103 ERROR_VARIABLE output
60104 RESULT_VARIABLE result
61105 )
62106
63107 if (result)
64108 message (FATAL_ERROR
65- "Calling '${CMAKE_C_COMPILER} --ver ' failed."
109+ "Calling '${CMAKE_C_COMPILER} ${_xc8_version_flag} ' failed."
66110 )
67111 endif ()
68112
69113 if (output MATCHES "XC8 C Compiler V([0-9]+\. [0-9]+)" )
70114 set (CMAKE_C_COMPILER_VERSION ${CMAKE_MATCH_1} PARENT_SCOPE)
71115 else ()
72116 message (FATAL_ERROR
73- "Failed to parse output of '${CMAKE_C_COMPILER} --ver '."
117+ "Failed to parse output of '${CMAKE_C_COMPILER} ${_xc8_version_flag} '."
74118 )
75119 endif ()
76120endfunction ()
0 commit comments