Up vote 5 down vote favorite 3 share g+ share fb share tw.
I have many source files in source directory. For example a. C, b.
C, c. C and want to compile it by gcc with -combine option. Set(CMAKE_C_FLAGS "-combine") set(SRC a.
C b. C c. C) add_executable(a.
Out ${SRC}) Cmake compiles each *. C file in object file, but I want to compile all sources to one object. How can I get this.
In terms of gcc: gcc -combine a. C b. C c.
C -o module. O ar rcs library. A module.
O But cmake uses per-module translation of sources. Gcc a. C -o a.
O gcc b. C -o b. O gcc c.
C -o c. O ar rcs library. A a.
O b. O c. O Translation with combine could speed up performance of program.
I couldn't use LTO which could resolve the same problem in cmake due to old version of gcc. Thanks. Gcc cmake combine link|improve this question edited Jun 15 '11 at 11:05 asked Jun 14 '11 at 16:45Igor Petushkov263.
I have a feeling that that's not what you're trying to do. Maybe you mean -fwhole-program, which is morally equivalent to concatenating all your source files together. But more likely you're just trying to make a reusable library.
Use -shared to make a dynamic library, or just use the ar program to combine lots of . O files into a static library. CMake can automate both for you.
– Kerrek SB Jun 14 '11 at 19:11 Yes, I'm sure. This option exist in gcc version 4. 4/4.5 – Igor Petushkov Jun 16 '11 at 8:29 Interesting, it disappeared in 4.6!
:-) What's its purpose? Anything you can't achieve with -fwhole-program? – Kerrek SB Jun 16 '11 at 10:37 Yes, 4.6 doesn't have -combine, but our team use gcc-4.3 and 4.4. There are the same problem with -fwhole-program as for combine, because it need to compile all source files in one compilation unit to create 1 object file.
– Igor Petushkov Jun 17 '11 at 7:03 I would also like to know the answer to this. I'm currently using a custom Makefile system instead of CMake but I'd like to switch. But performance via inter-module optimization is more important than CMake.
– Zan Lynx Sep 6 '11 at 20:56.
Use add_custom_target/add_custom_command. In any way it is non-portable construction, so here simple example project root with two folders in it src - here N files, build for binary, and CMakeLists. Txt cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR) set(TARGET_NAME whole) project(${TARGET_NAME} C) file(GLOB SRC_FILES src/*.
C) add_custom_target(${TARGET_NAME} ${CMAKE_C_COMPILER} -flto -fwhole-program ${SRC_FILES} -o ${TARGET_NAME}) In build folder run cmake ..; make VERBOSE=1 whole This will make the work for you. But, -fwhole-program work only with executable, as per documentation. -fwhole-program Assume that the current compilation unit represents the whole program being compiled.
All public functions and variables with the exception of main and those merged by attribute externally_visible become static functions and in effect are optimized more aggressively by interprocedural optimizers. So you mast have main defined anywhere in your source files.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.