Skip to content

Instantly share code, notes, and snippets.

@lchagnoleau
Created May 23, 2024 11:27
Show Gist options
  • Save lchagnoleau/74383d05879ef8fae4b921e7ee66e26d to your computer and use it in GitHub Desktop.
Save lchagnoleau/74383d05879ef8fae4b921e7ee66e26d to your computer and use it in GitHub Desktop.
CMake multiple target by list
cmake_minimum_required(VERSION 3.21)
project(cmake_test LANGUAGES C)
set(target "t1" "t2" "t3")
foreach(t ${target})
set(MESSAGE_TEXT "Hello, ${t}")
add_executable(${t} main.c)
target_compile_definitions(${t} PRIVATE MESSAGE_TEXT="${MESSAGE_TEXT}")
endforeach()
#include <stdio.h>
#ifndef MESSAGE_TEXT
#define MESSAGE_TEXT "Hello, World!"
#endif
int main() {
printf("%s\n", MESSAGE_TEXT);
return 0;
}
@lchagnoleau
Copy link
Author

cmake -Bbuild
cmake --build
❯ ./build/t1
Hello, t1
❯ ./build/t2
Hello, t2
❯ ./build/t3
Hello, t3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment