Created
March 29, 2021 17:23
-
-
Save yeputons/123fe9fe309c3ad94da70d95414e0361 to your computer and use it in GitHub Desktop.
GCC's include option with CMake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
run(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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