Skip to content

Instantly share code, notes, and snippets.

@harderthan
Last active September 19, 2022 12:53
Show Gist options
  • Save harderthan/6016485dec0b37ca02c4f0b20bb17e5d to your computer and use it in GitHub Desktop.
Save harderthan/6016485dec0b37ca02c4f0b20bb17e5d to your computer and use it in GitHub Desktop.
cmake configure_file() example
cmake_minimum_required(VERSION 3.16.3)
project(configure-file-example)
# Configure file, export the environment variable.
set(FOO_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/${PATH_YOU_WANT}")
configure_file(config/foo.h.in foo.h @ONLY)
# Libraries or excutables
# ...
include_directories(
${CMAKE_CURRENT_BINARY_DIR})
#ifndef FOO_H
#define FOO_H
#include <string>
#define FOO_DIR @FOO_DIR@
std::string GetFooDir() {
std::string path = "@FOO_DIR@";
return path;
}
#endif // FOO_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment