Last active
September 19, 2022 12:53
-
-
Save harderthan/6016485dec0b37ca02c4f0b20bb17e5d to your computer and use it in GitHub Desktop.
cmake configure_file() example
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.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}) |
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
#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