flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > High Level Languages > simplify libjpeg build system?

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 323

simplify libjpeg build system?

Build systems for libjpeg (and for pretty much everything in c) are so confusing. They are made to support every processor, os, and compiler, and because of that they are nearly unreadable.

I want to take libjpeg-turbo-1.5.3 source, and delete everything unrelated to my system (32 bit windows + vs2005 compiler). Just so I can understand what is going on. I will use CMakeLists.txt for that.

I wonder if I can delete, for example, turbojpeg-mapfile.jni . What it is for, java?
Post 12 Apr 2018, 07:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15643
Location: Thasus

Re: simplify libjpeg build system?


vivik wrote:
Build systems for libjpeg (and for pretty much everything in c) are so confusing. They are made to support every processor, os, and compiler, and because of that they are nearly unreadable.

Only "nearly" unreadable? You mean someone can actually read them? Shocked
Post 12 Apr 2018, 07:57
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 323

How I compile libjpeg and libpng.

I have folders:


Code:
C:/_src
C:/_build
C:/_install



I dropped libjpeg-turbo-1.5.3 and libpng-1.6.34 in _src.
I created same folders in _build, and moved in them in command line.
And used this command:


Code:
cmake -G"Visual Studio 8 2005" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=C:/_install C:/_src/libjpeg-turbo-1.5.3



(Probably can use -DCMAKE_BUILD_TYPE=Release or -DCMAKE_BUILD_TYPE=RelWithDebInfo instead.)

After that, I opened the generated <something>.sln file, compiled <something>-static project in it, and then "compiled" the INSTALL project.

Now I have some header files in the _install/include and some object files in _install/lib (don't forget to add those paths in "tools -- options -- projects and solutions -- directories"). I can use them in my programs by adding those lines in them:


Code:
#include <jpeglib.h>
#pragma comment(lib,"jpeg-static.lib")

#include <png.h>
#pragma comment(lib,"libpng16_staticd.lib")

#include <zlib.h>
#pragma comment(lib,"zlibstaticd.lib")



"d" stands for "debug". I will switch to "release" versions once I'll get comfortable with everything.

(my cmake --version is 3.10.2. A reminder to not install anything more modern, since they are threating to deprecate vs2005 support)


Last edited by vivik on 12 Apr 2018, 16:43; edited 1 time in total
Post 12 Apr 2018, 16:18
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 323

There is this comment in c:/_src/libjpeg-turbo-1.5.3/CMakeLists.txt , not sure what it means.


Code:
This does nothing except when using MinGW.  CMAKE_BUILD_TYPE has no meaning
in Visual Studioand it always defaults to Debug when using NMake.
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")

This only works if building from the command line.  There is currently no way
to set a variable's value based on the build type when using Visual Studio.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(BUILD "${BUILD}d")
endif()

Post 12 Apr 2018, 16:33
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 323

One thing that will make my life easier, is making sure that my static libraries and my main program use the same version of runtime library. In visual studio it is specified in "c/c++ -- code generation -- runtime library". I've set it to "multi-threaded debug /MTd". I hope I could disable it entirely, but, not now.

To set it in cmake, I will need something like this:


Code:
if(MSVC)
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif()



Or use set(CMAKE_CXX_FLAGS "something")

Extra info: https://stackoverflow.com/questions/14148374/how-do-you-set-properties-in-a-vcproj-file-with-cmake

Huh, there already is something related to that in c:/_src/libjpeg-turbo-1.5.3/CMakeLists.txt


Code:
if(MSVC)
  option(WITH_CRT_DLL
    "Link all libjpeg-turbo libraries and executables with the C run-time DLL (msvcr*.dll) instead of the static C run-time library (libcmt*.lib.)  The default is to use the C run-time DLL only with the libraries and executables that need it."
    FALSE)
  if(NOT WITH_CRT_DLL)
    # Use the static C library for all build types
    foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
      if(${varMATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${var"${${var}}")
      endif()
    endforeach()
  endif()
  add_definitions(-W3 -wd4996)
endif()



Replaced code above with this, for now:


Code:
if(MSVC)
  set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
  set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
  add_definitions(-W3 -wd4996) #LATERwhat is this?
endif()

Post 12 Apr 2018, 16:58
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 323

Need to write CMakeLists.txt for giflib, and clean it up for libjpeg, libpng and zlib.

Look how each library uses "option" from cmake.

Reference: https://cmake.org/cmake/help/v3.10/command/option.html

>Provide an option for the user to select as ON or OFF. If no initial value is provided, OFF is used.

libjpeg:


Code:
option(WITH_SIMD "Include SIMD extensions" TRUE)



libpng:


Code:
option(PNG_BUILD_ZLIB "Custom zlib Location, else find_package is used" OFF)



zlib:


Code:
option(ASM686 "Enable building i686 assembly implementation")



...What do you like more, ON OFF, or TRUE FALSE?

I guess I'll go for TRUE FALSE, they are harder to mix up.
Post 12 Apr 2018, 17:49
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 323

I'd like libjpeg to also add "d" prefix for its debug build, just like libpng and zlib. This way I'll never have to recompile them again.

I'll add this in CMakeLists.txt:


Code:
set(CMAKE_DEBUG_POSTFIX "d")



Also, I'll include those libraries like this:


Code:
// https://stackoverflow.com/questions/2290509/debug-vs-ndebug/29253284
#ifdef _DEBUG

#include <jpeglib.h>
#pragma comment(lib,"jpeg-staticd.lib")

#include <png.h>
#pragma comment(lib,"libpng16_staticd.lib")

#include <zlib.h>
#pragma comment(lib,"zlibstaticd.lib")

#else

#include <jpeglib.h>
#pragma comment(lib,"jpeg-static.lib")

#include <png.h>
#pragma comment(lib,"libpng16_static.lib")

#include <zlib.h>
#pragma comment(lib,"zlibstatic.lib")

#endif

Post 14 Apr 2018, 17:24
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 323

Also, I'll add _build.bat into each c:/_build subdirectory, with content like this:


Code:
cmake -G"Visual Studio 8 2005" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=C:/_install C:/_src/libjpeg-turbo-1.5.3
pause



This way I can just double click it when I need to rerun cmake. And I'll need to do that often, since I'm changing the build scripts themselves.
Post 14 Apr 2018, 17:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.