Skip to content

Instantly share code, notes, and snippets.

@yeputons
Created March 29, 2021 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeputons/123fe9fe309c3ad94da70d95414e0361 to your computer and use it in GitHub Desktop.
Save yeputons/123fe9fe309c3ad94da70d95414e0361 to your computer and use it in GitHub Desktop.
GCC's include option with CMake
cmake_minimum_required(VERSION 3.10)
project(gcc-include-demo CXX)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Make sure it's specified before add_executable.
# Includes pre-main.inc.cpp in all translation units in all projects.
# Use target_compile_options to include it in all translation units for a specific target only.
add_compile_options(-include pre-main.inc.cpp)
else()
error("Only GCC is supported")
endif()
add_executable(main main.cpp)
int main() {
run();
}
#include <cstdio>
void run() {
std::printf("run()\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment