diff --git a/CMakeLists.txt b/CMakeLists.txt index 302be99..baabf9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,12 @@ # This file was generated automatically by cmkr. +# Regenerate CMakeLists.txt file when necessary +include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT) + +if(CMKR_INCLUDE_RESULT) + cmkr() +endif() + cmake_minimum_required(VERSION 3.15) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/src/gen.cpp b/src/gen.cpp index 065e4b3..2375036 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -111,9 +111,9 @@ int generate_cmake(const char *path) { std::stringstream ss; ss << "# This file was generated automatically by cmkr.\n"; ss << "\n"; - + ss << "# Regenerate CMakeLists.txt file when necessary\n"; - ss << "include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)\n"; + ss << "include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)\n\n"; ss << "if(CMKR_INCLUDE_RESULT)\n"; ss << "\tcmkr()\n"; ss << "endif()\n"; @@ -225,14 +225,19 @@ int generate_cmake(const char *path) { } else { set_val = std::get(set.val) ? "ON" : "OFF"; } - ss << "set(" << set.name << " " << set_val;; + ss << "set(" << set.name << " " << set_val; + ; if (set.cache) { std::string typ; - if (set.val.index() == 1) typ = "STRING"; else typ = "BOOL"; - ss << " CACHE " << typ << " \"" << set.comment << "\""; - if (set.force) ss << " FORCE"; + if (set.val.index() == 1) + typ = "STRING"; + else + typ = "BOOL"; + ss << " CACHE " << typ << " \"" << set.comment << "\""; + if (set.force) + ss << " FORCE"; } - ss << ")\n\n"; + ss << ")\n\n"; } } @@ -364,7 +369,11 @@ int generate_cmake(const char *path) { ss << conf << " "; } } - ss << "\n\tDESTINATION " << inst.destination << "\n\t)\n\n"; + ss << "\n\tDESTINATION " << inst.destination << "\n\t"; + if (!inst.targets.empty()) + ss << "COMPONENT " << inst.targets[0] << "\n\t)\n\n"; + else + ss << "\n\t)\n\n"; } }