Created
February 3, 2018 01:19
-
-
Save EricWF/51a99c2a6fcbb825c4b96eb75ce515d9 to your computer and use it in GitHub Desktop.
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
project(test-cmake CXX) | |
cmake_minimum_required(VERSION 3.9) | |
# | |
set(header_in ${CMAKE_CURRENT_BINARY_DIR}/header.in) | |
file(WRITE ${header_in} | |
" | |
#ifndef MY_HEADER | |
#define MY_HEADER | |
int my_x = 42; | |
#endif | |
" | |
) | |
set(header_file ${CMAKE_CURRENT_BINARY_DIR}/header.h) | |
add_custom_command(OUTPUT ${header_file} | |
COMMAND cp ${header_in} ${header_file} | |
DEPENDS ${header_in} | |
) | |
set_source_files_properties(${header_file} PROPERTIES GENERATED TRUE) | |
add_custom_target(my_headers DEPENDS ${header_file}) | |
include_directories(${CMAKE_CURRENT_BINARY_DIR}) | |
add_library(my_lib STATIC libfile.cpp ${header_file}) | |
add_dependencies(my_lib my_headers) |
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 HEADER_H | |
#define HEADER_H | |
int my_x = 42; | |
#endif // HEADER_H |
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 "header.h" | |
int foo() { | |
return my_x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment