|
|
(4 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| [[CMake_User_Contributed_Macros|Back]]
| | {{CMake/Template/Moved}} |
|
| |
|
| Sometimes it's faster (and the compiler might be able to optimize better) to include all source files of a project into one source file and compile only this one file instead of all files each one by one. This can be done with the macro CREATE_FINAL_FILE().
| | This page has moved [https://gitlab.kitware.com/cmake/community/wikis/contrib/macros/CreateFinalFile here]. |
| | |
| Usage is like this:
| |
| | |
| -----
| |
| | |
| SET(app_SRCS main.cpp app.cpp bar.c foo.c)
| |
| OPTION(ENABLE_FINAL "Enable final all-in-one compilation.")
| |
| IF(ENABLE_FINAL)
| |
| CREATE_FINAL_FILE(_final.cpp ${_app_SRCS} )
| |
| ADD_EXECUTABLE(foo _final.cpp)
| |
| ELSE(ENABLE_FINAL)
| |
| ADD_EXECUTABLE(foo ${app_SRCS} )
| |
| ENDIF(ENABLE_FINAL)
| |
| -----
| |
| | |
| This example creates an executable named "foo" from the sources main.cpp, app.cpp, bar.c and foo.c. If the option "ENABLE_FINAL" is enabled, these for files will be included in the file "_final.cpp" and only this will be compiled. Otherwise the four source files are compiled one by one as you know it.
| |
| And here comes the macro:
| |
| | |
| -----
| |
| | |
| MACRO(CREATE_FINAL_FILE _filename)
| |
| FILE(WRITE ${_filename} "//autogenerated file\n")
| |
| FOREACH (_current_FILE ${ARGN})
| |
| FILE(APPEND ${_filename} "#include \"${_current_FILE}\"\n")
| |
| ENDFOREACH (_current_FILE)
| |
| ENDMACRO(CREATE_FINAL_FILE _filename)
| |
|
| |
| | |
| -----
| |
| [[CMake_User_Contributed_Macros|Back]]
| |
| | |
| {{CMake/Template/Footer}}
| |
Latest revision as of 15:41, 30 April 2018