@dehilster (David de Hilster) posted a new topic, subject "CMake generating much smaller *.a files than makefile". It read:

   When converting from makefile to CMake, the resulting file sizes are hugely different.
    
    size with makefile: 266k  
    size with cmake: 33K
    
    Here are the files. Any insight would be very helpful!
    
    **Makefile:**
    [code] 
        LIBOBJ = dir.o io.o libprim.o list.o prim.o sm.o str.o dyn.o u_out.o
        TARG	= libprim.a
        CC	= g++
        CFLAGS	= -g -DLINUX -I../../include/Api -I../include -Wno-write-strings
        
        %.o: %.cpp
        	$(CC) $(CFLAGS) -c $< -o $@
        
        all: $(TARG)
        $(TARG): $(LIBOBJ)
        	ar r $(TARG) $(LIBOBJ)
        	ranlib $(TARG)
        	cp $(TARG) ../../lib
        
        clean:
        	/bin/rm -f $(TARG) *.o
        
    [/code]
    
    **CMakeLists.txt:**
    [code] 
        include_directories(../../include/Api)
        include_directories(../include)
        
        add_definitions( -DLIBPRIM_EXPORTS )
        if(WIN32)
          add_definitions( -DMSVC_VERSION=${MSVC_VERSION} -D_CRT_SECURE_NO_WARNINGS )
        else()
          add_definitions( -DLINUX -Wno-write-strings)
        endif()
        
        add_library(libprim STATIC
            dir.cpp
            io.cpp
            libprim.cpp
            list.cpp
            prim.cpp
            sm.cpp
            str.cpp
            dyn.cpp
            u_out.cpp
        )
    [/code]

So @dehilster (David de Hilster) replied

    Could it be the **ar** and **ranlib**?

Then @hsattler (Hendrik Sattler) said

    The Makefile version has the -g flag. Maybe you built the Release version with CMake and the difference is optimization and no debug symbols?

@dehilster (David de Hilster) replied

    I will look into it.

To which @dehilster (David de Hilster) replied

    That was it! Simply adding set(CMAKE_BUILD_TYPE Debug) made it the same size. Thx!


{'source': 'discourse', 'url': 'https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816', 'title': 'CMake generating much smaller *.a files than makefile', 'views': 236, 'has_accepted_answer': True, 'word_count': 185, 'like_count': 0, 'reply_count': 1, 'participant_count': 2, 'posts': 5, 'tags': '', 'author': '@dehilster (David de Hilster)', 'participants': '@dehilster (David de Hilster), @hsattler (Hendrik Sattler)', 'image_url': [None], 'created_at': '2020-09-10T15:26:48.914Z', 'last_posted_at': '2020-09-10T15:39:40.480Z'}