Skip to content

Commit

Permalink
cmake check for m library;
Browse files Browse the repository at this point in the history
use m library on FreeBSD for linking of specific programs
  • Loading branch information
zdenop committed Jan 6, 2024
1 parent c868936 commit d5c36c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ else() # SW_BUILD=ON
-DHAVE_LIBJP2K=1)
endif()

set(libs_private "${libs_private} -lm")
check_library_exists(m sin "" HAVE_LIBM)

This comment has been minimized.

Copy link
@stweil

stweil Jan 6, 2024

Collaborator

@zdenop, this breaks the cmake build for Ubuntu:

  Unknown CMake command "check_library_exists".

This comment has been minimized.

Copy link
@diizzyy

diizzyy Jan 6, 2024

Contributor

Same on FreeBSD (cmake 3.27.9)

It's missing include(CheckLibraryExists)

This comment has been minimized.

Copy link
@stweil

stweil Jan 7, 2024

Collaborator

Thank you. I could fix it now in commit f3a45c5.

if(HAVE_LIBM)
set(libs_private "${libs_private} -lm")
endif(HAVE_LIBM)

if(${CMAKE_SYSTEM_NAME} MATCHES "kFreeBSD.*|DragonFly.*|FreeBSD")
set(FREEBSD ON)
endif(${CMAKE_SYSTEM_NAME} MATCHES "kFreeBSD.*|DragonFly.*|FreeBSD")

# ##############################################################################
#
Expand Down
9 changes: 8 additions & 1 deletion prog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

set(math_progs "dna_reg|extrema_reg|insert_reg|locminmax_reg|numa1_reg|otsutest1|plottest|pta_reg|rotatefastalt|watershed_reg")

########################################
# FUNCTION add_prog_target
########################################
Expand All @@ -12,7 +15,11 @@ function(add_prog_target target)
if (BUILD_SHARED_LIBS)
target_compile_definitions (${target} PRIVATE -DLIBLEPT_IMPORTS)
endif()
target_link_libraries (${target} leptonica)
if(FREEBSD AND HAVE_LIBM AND ${target} MATCHES ${math_progs})
target_link_libraries (${target} leptonica m)
else()
target_link_libraries (${target} leptonica)
endif()
set_target_properties (${target} PROPERTIES FOLDER prog)
endfunction(add_prog_target)
########################################
Expand Down

3 comments on commit d5c36c8

@zdenop
Copy link
Collaborator Author

@zdenop zdenop commented on d5c36c8 Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stweil : thanks. I think I need to downgrade my cmake

@DanBloomberg
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be relevant, but ooking at set(math_progs) ...
there are more programs that include math.h, namely

grep "<math.h>" *.c
contrasttest.c:#include <math.h>
dna_reg.c:#include <math.h>
extrema_reg.c:#include <math.h>
fpix1_reg.c:#include <math.h>
gammatest.c:#include <math.h>
gifio_reg.c:#include <math.h>
insert_reg.c:#include <math.h>
jp2kio_reg.c:#include <math.h>
locminmax_reg.c:#include <math.h>
numa1_reg.c:#include <math.h>
numa2_reg.c:#include <math.h>
numa3_reg.c:#include <math.h>
otsutest1.c:#include <math.h>
pixalloc_reg.c:#include <math.h>
pixcomp_reg.c:#include <math.h>
plottest.c:#include <math.h>
pta_reg.c:#include <math.h>
rankhisto_reg.c:#include <math.h>
rotatefastalt.c:#include <math.h>   /* required for sin and tan */
warper_reg.c:#include <math.h>
watershed_reg.c:#include <math.h>
webpio_reg.c:#include <math.h>

@stweil
Copy link
Collaborator

@stweil stweil commented on d5c36c8 Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that they get -lm because the linker flags for libopenjp2, libpng, libtiff-4, libwebp and other libraries also add -lm.

Please sign in to comment.