cmake_minimum_required(VERSION 3.10) project(HelloWorld) set(CMAKE_PREFIX_PATH "C:/Program Files/CMake/bin") # Enable incremental linking for faster builds if(MSVC) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") add_compile_options(/MP) # Enable parallel builds add_compile_options(/Zi) # Generate debug information add_link_options(/DEBUG /INCREMENTAL) # Enable incremental linking endif() # For GCC/Clang, enable incremental build optimizations if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") add_compile_options(-g -pipe) # Debug info and faster compilation add_link_options(-Wl,--incremental) # Enable incremental linking endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enable faster compilation for incremental builds if(MSVC) # MSVC specific optimizations add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() add_executable(hello_world main.cpp) add_executable(hello_world subfunc.cpp) # Set output directory for executables set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # For Visual Studio generators, also set the output directory specifically if(MSVC) set_target_properties(hello_world PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) endif() # Add dependency tracking for better incremental builds set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY CMAKE_CONFIGURE_DEPENDS ) # Create a custom target for quick rebuilds add_custom_target(quick COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target hello_world COMMENT "Quick build of hello_world target only" )