The Rambam [Melachim 6-4] writes:
ואם לא השלימו או שהשלימו ולא קבלו שבע מצות עושין עמהם מלחמה והורגין כל הזכרים הגדולים ובוזזין כל ממונם וטפם ואין הורגין אשה ולא קטן שנאמר והנשים והטף זה טף של זכרים במה דברים אמורים במלחמת הרשות שהוא עם שאר האומות אבל שבעה עממין ועמלק שלא השלימו אין מניחין מהם נשמה שנאמר כן תעשה לכל וגו' רק מערי העמים לא תחיה כל נשמה
If they do not agree to a peaceful settlement, or if they agree to a peaceful settlement, but refuse to accept the seven mitzvos, war should be waged against them.
All males past majority should be killed. Their money and their children should be taken as spoil, but neither women or children should be killed, as Deuteronomy 20:14 states: 'But the women and the children... take as spoil." 'The children' refer to males below the age of majority.
The above applies to a milchemes hareshus fought with other nations. However, if either the seven nations or Amalek refuse to accept a peaceful settlement, not one soul of them may be left alive as ibid. 20:15-16 states: 'Do this to all the cities that ... are not the cities of these nations. However, from the cities of these nations,... do not leave a soul alive.'
Now there are three types of מלחמת מצוה [Melachim 5-1] - 1] a war against Amalek, 2] the seven nations and 3] עזרת ישראל מיד הצר שבא עליהם, defending ourselves against attacking nations. The Rambam makes a distinction here between מלחמת רשות and a war against the seven nations and Amalek but failed to mention what the din would be if the war was a protective one. So is when protecting ourselves, do we just kill the males or everyone?