Last active
December 27, 2015 20:19
-
-
Save Madsy/7384008 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
#CMake script: | |
SET( ${PROJECT_NAME}_SOURCES | |
main.cpp | |
) | |
#main.x depends on main.cpp (is generated based on main.cpp) | |
#main.o depends on main.cpp and main.x (main.x is included in main.cpp) | |
#So if main.cpp changes, first run the tool to create main.x, | |
#then run cc to create main.o from main.cpp and main.x | |
ADD_CUSTOM_COMMAND( | |
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
OUTPUT ${PROJECT_SOURCE_DIR}/main.x | |
COMMAND ./tool.sh main.cpp main.x | |
DEPENDS ${PROJECT_SOURCE_DIR}/main.cpp | |
) | |
SET_PROPERTY(SOURCE ${PROJECT_SOURCE_DIR}/main.cpp} | |
APPEND PROPERTY OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/main.x) | |
ADD_EXECUTABLE(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES}) | |
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ) | |
###########main.cpp############## | |
#include <cstdio> | |
#include "main.x" | |
int main() | |
{ | |
printf("%s\n", txt); | |
return 0; | |
} | |
#############tool.sh############### | |
#!/bin/bash | |
echo "const char* txt = \"$1\"" >> $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment