Preheat the oven to 350°F (175°C). Grease and flour two 9-inch round cake pans.
In a large mixing bowl, whisk together the flour, sugar, baking powder, baking soda, cinnamon, and salt until well combined.
In another bowl, combine the vegetable oil, eggs, grated carrots, crushed pineapple, and vanilla extract. Mix until thoroughly blended.
Gradually add the wet ingredients to the dry ingredients, stirring until just combined. If using, fold in the chopped nuts.
Divide the batter evenly between the prepared cake pans. Bake for 25-30 minutes, or until a toothpick inserted into the center comes out clean.
Allow the cakes to cool in the pans for 10 minutes, then transfer them to wire racks to cool completely.
While the cakes are cooling, prepare the cream cheese frosting. In a medium bowl, beat the softened cream cheese and butter together until smooth. Gradually add the powdered sugar and vanilla extract, mixing until creamy and well combined.
Once the cakes are completely cool, spread a layer of cream cheese frosting on top of one cake layer, then place the second layer on top. Frost the top and sides of the cake with the remaining cream cheese frosting.
Serve immediately or refrigerate for up to 3 days.