Skip to content

Commit 27bc309

Browse files
authored
Improve a couple of CMake checks
1 parent bc57c70 commit 27bc309

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

CMakeLists.txt

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -450,32 +450,45 @@ if(BZIP2_FOUND)
450450
option(PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON)
451451
endif()
452452
if(PCRE2_SUPPORT_LIBBZ2)
453-
include_directories(${BZIP2_INCLUDE_DIR})
453+
if(BZIP2_FOUND)
454+
include_directories(${BZIP2_INCLUDE_DIR})
455+
else()
456+
message(
457+
FATAL_ERROR
458+
" libbz2 not found. Set BZIP2_INCLUDE_DIR to a compatible header\n"
459+
" or set BZip2_ROOT to a full bzip2 installed tree, as needed."
460+
)
461+
endif()
454462
endif()
455463

456464
# zlib
457465
if(ZLIB_FOUND)
458466
option(PCRE2_SUPPORT_LIBZ "Enable support for linking pcre2grep with libz." ON)
459467
endif()
460468
if(PCRE2_SUPPORT_LIBZ)
461-
include_directories(${ZLIB_INCLUDE_DIR})
469+
if(ZLIB_FOUND)
470+
include_directories(${ZLIB_INCLUDE_DIR})
471+
else()
472+
message(
473+
FATAL_ERROR
474+
" zlib not found. Set ZLIB_INCLUDE_DIR to a compatible header\n"
475+
" or set ZLIB_ROOT to a full zlib installed tree, as needed."
476+
)
477+
endif()
462478
endif()
463479

464480
# editline lib
465481
if(EDITLINE_FOUND)
466482
option(PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF)
467483
endif()
468-
if(EDITLINE_FOUND)
469-
if(PCRE2_SUPPORT_LIBEDIT)
484+
if(PCRE2_SUPPORT_LIBEDIT)
485+
if(EDITLINE_FOUND)
470486
include_directories(${EDITLINE_INCLUDE_DIR})
471-
endif()
472-
else()
473-
if(PCRE2_SUPPORT_LIBEDIT)
487+
else()
474488
message(
475489
FATAL_ERROR
476-
" libedit not found, set EDITLINE_INCLUDE_DIR to a compatible header\n"
477-
" or set Editline_ROOT to a full libedit installed tree, as needed\n"
478-
" Might need to enable policy CMP0074 in CMakeLists.txt"
490+
" libedit not found. Set EDITLINE_INCLUDE_DIR to a compatible header\n"
491+
" or set Editline_ROOT to a full libedit installed tree, as needed."
479492
)
480493
endif()
481494
endif()
@@ -485,7 +498,15 @@ if(READLINE_FOUND)
485498
option(PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON)
486499
endif()
487500
if(PCRE2_SUPPORT_LIBREADLINE)
488-
include_directories(${READLINE_INCLUDE_DIR})
501+
if(READLINE_FOUND)
502+
include_directories(${READLINE_INCLUDE_DIR})
503+
else()
504+
message(
505+
FATAL_ERROR
506+
" libreadline not found. Set READLINE_INCLUDE_DIR to a compatible header\n"
507+
" or set Readline_ROOT to a full libreadline installed tree, as needed."
508+
)
509+
endif()
489510
endif()
490511

491512
# Prepare build configuration
@@ -1493,7 +1514,12 @@ if(PCRE2_SHOW_REPORT)
14931514
endforeach()
14941515
else()
14951516
string(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
1496-
message(STATUS " C compiler flags .................. : ${CMAKE_C_FLAGS}${CFSP}${CMAKE_C_FLAGS_${buildtype}}")
1517+
if(buildtype STREQUAL "")
1518+
set(CFBLD "")
1519+
else()
1520+
set(CFBLD "${CMAKE_C_FLAGS_${buildtype}}")
1521+
endif()
1522+
message(STATUS " C compiler flags .................. : ${CMAKE_C_FLAGS}${CFSP}${CFBLD}")
14971523
endif()
14981524

14991525
message(STATUS "")

cmake/PCRE2UseSystemExtensions.cmake

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,53 @@ function(pcre2_use_system_extensions)
2828
cmake_push_check_state(RESET)
2929
set(
3030
_pcre2_test_src
31-
"
32-
#include <sys/time.h>
33-
#include <sys/resource.h>
31+
[=[
32+
#include <sys/time.h>
33+
#include <sys/resource.h>
3434

35-
int main(void) {
36-
struct rlimit rlim;
37-
getrlimit(RLIMIT_STACK, &rlim);
38-
return 0;
39-
}
40-
"
35+
int main(void) {
36+
struct rlimit rlim;
37+
getrlimit(RLIMIT_STACK, &rlim);
38+
return 0;
39+
}
40+
]=]
4141
)
4242
set(CMAKE_REQUIRED_QUIET TRUE)
4343
check_c_source_compiles("${_pcre2_test_src}" _HAVE_GETRLIMIT_NAKED)
4444

4545
if(NOT _HAVE_GETRLIMIT_NAKED)
4646
# Try again with _ALL_SOURCE
47+
if(NOT _HAVE_GETRLIMIT_ALLSOURCE)
48+
set(_allsource_first_run TRUE)
49+
endif()
4750
set(CMAKE_REQUIRED_DEFINITIONS "-D_ALL_SOURCE")
4851
check_c_source_compiles("${_pcre2_test_src}" _HAVE_GETRLIMIT_ALLSOURCE)
4952
unset(CMAKE_REQUIRED_DEFINITIONS)
5053

5154
if(_HAVE_GETRLIMIT_ALLSOURCE)
52-
message(STATUS "Detected platform feature gate _ALL_SOURCE")
5355
add_compile_definitions(_ALL_SOURCE)
56+
if(_allsource_first_run)
57+
message(STATUS "Detected platform feature gate _ALL_SOURCE")
58+
endif()
5459
endif()
5560
endif()
5661

5762
check_symbol_exists(mkostemp stdlib.h _HAVE_MKOSTEMP_NAKED)
5863

5964
if(NOT _HAVE_MKOSTEMP_NAKED)
6065
# Try again with _GNU_SOURCE
66+
if(NOT _HAVE_MKOSTEMP_GNUSOURCE)
67+
set(_gnusource_first_run TRUE)
68+
endif()
6169
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
6270
check_symbol_exists(mkostemp stdlib.h _HAVE_MKOSTEMP_GNUSOURCE)
6371
unset(CMAKE_REQUIRED_DEFINITIONS)
6472

6573
if(_HAVE_MKOSTEMP_GNUSOURCE)
66-
message(STATUS "Detected platform feature gate _GNU_SOURCE")
6774
add_compile_definitions(_GNU_SOURCE)
75+
if(_gnusource_first_run)
76+
message(STATUS "Detected platform feature gate _GNU_SOURCE")
77+
endif()
6878
endif()
6979
endif()
7080

0 commit comments

Comments
 (0)