From 2511f03a889980142d2a134f25aeb3b98f716723 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 8 Jan 2023 12:35:22 +0700 Subject: [PATCH] add support in test project to choose C and/or C++ to compile --- test/CMakeLists.txt | 10 +++++++++- test/hello_world.c | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/hello_world.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 135aa7f..27c7acd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,9 +1,17 @@ cmake_minimum_required(VERSION 3.0) project(test) +option(BUILD_C "build hello world in C Language" OFF) +option(BUILD_CXX "build hello world in CXX Language" ON) option(BUILD_TXT "build hello world txt file" OFF) -add_executable(hello_world hello_world.cpp) +if(BUILD_C) + add_executable(hello_world_c hello_world.c) +endif() + +if(BUILD_CXX) + add_executable(hello_world hello_world.cpp) +endif() if(BUILD_TXT) add_custom_target( diff --git a/test/hello_world.c b/test/hello_world.c new file mode 100644 index 0000000..7791fbb --- /dev/null +++ b/test/hello_world.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello world!\n"); + return 0; +}