Skip to content

Commit d01cd71

Browse files
authored
cmake: set PCRE2POSIX_CFLAG in pcre2-config and pkg-config (#311)
Since a8a875e (windows: integrate visibility attributes without conflicts (#249), 2023-05-16) setting CFLAGS when using a DLL is recommended, but the pcre2-config and pkgconfig files generated by cmake didn't include that logic, unlike the ones generated by the autotools. While at it, refactor the code so it will be more modern and it wouldn't unnecessarily install the pcre2posix pkgconfig if not needed and make sure the generated pcre2-config uses UNIX EOL.
1 parent 3f05f72 commit d01cd71

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

CMakeLists.txt

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -573,46 +573,6 @@ IF(WIN32)
573573
SET(CMAKE_DEBUG_POSTFIX "d")
574574
ENDIF(WIN32)
575575

576-
# Generate pkg-config files
577-
578-
SET(PACKAGE_VERSION "${PCRE2_MAJOR}.${PCRE2_MINOR}")
579-
SET(prefix ${CMAKE_INSTALL_PREFIX})
580-
581-
SET(exec_prefix "\${prefix}")
582-
SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
583-
SET(includedir "\${prefix}/include")
584-
IF(WIN32 AND (CMAKE_BUILD_TYPE MATCHES Debug))
585-
SET(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX})
586-
ENDIF()
587-
CONFIGURE_FILE(libpcre2-posix.pc.in libpcre2-posix.pc @ONLY)
588-
SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-posix.pc")
589-
590-
IF(PCRE2_BUILD_PCRE2_8)
591-
CONFIGURE_FILE(libpcre2-8.pc.in libpcre2-8.pc @ONLY)
592-
SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-8.pc")
593-
SET(enable_pcre2_8 "yes")
594-
ELSE()
595-
SET(enable_pcre2_8 "no")
596-
ENDIF()
597-
598-
IF(PCRE2_BUILD_PCRE2_16)
599-
CONFIGURE_FILE(libpcre2-16.pc.in libpcre2-16.pc @ONLY)
600-
SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-16.pc")
601-
SET(enable_pcre2_16 "yes")
602-
ELSE()
603-
SET(enable_pcre2_16 "no")
604-
ENDIF()
605-
606-
IF(PCRE2_BUILD_PCRE2_32)
607-
CONFIGURE_FILE(libpcre2-32.pc.in libpcre2-32.pc @ONLY)
608-
SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-32.pc")
609-
SET(enable_pcre2_32 "yes")
610-
ELSE()
611-
SET(enable_pcre2_32 "no")
612-
ENDIF()
613-
614-
CONFIGURE_FILE(pcre2-config.in pcre2-config @ONLY)
615-
616576
# Character table generation
617577

618578
OPTION(PCRE2_REBUILD_CHARTABLES "Rebuild char tables" OFF)
@@ -797,7 +757,8 @@ IF(PCRE2_BUILD_PCRE2_8)
797757
VERSION ${LIBPCRE2_POSIX_VERSION}
798758
SOVERSION ${LIBPCRE2_POSIX_SOVERSION}
799759
OUTPUT_NAME pcre2-posix)
800-
TARGET_COMPILE_DEFINITIONS(pcre2-posix-shared PUBLIC PCRE2POSIX_SHARED)
760+
set(PCRE2POSIX_CFLAG "-DPCRE2POSIX_SHARED")
761+
TARGET_COMPILE_DEFINITIONS(pcre2-posix-shared PUBLIC ${PCRE2POSIX_CFLAG})
801762
TARGET_LINK_LIBRARIES(pcre2-posix-shared pcre2-8-shared)
802763
SET(targets ${targets} pcre2-posix-shared)
803764
SET(dll_pdb_files ${PROJECT_BINARY_DIR}/pcre2-8.pdb ${dll_pdb_files})
@@ -954,6 +915,46 @@ IF(PCRE2_BUILD_PCRE2_32)
954915
ENDIF(BUILD_STATIC_LIBS)
955916
ENDIF(PCRE2_BUILD_PCRE2_32)
956917

918+
# Generate pkg-config files
919+
920+
set(PACKAGE_VERSION "${PCRE2_MAJOR}.${PCRE2_MINOR}")
921+
set(prefix ${CMAKE_INSTALL_PREFIX})
922+
923+
set(exec_prefix "\${prefix}")
924+
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
925+
set(includedir "\${prefix}/include")
926+
if(WIN32 AND (CMAKE_BUILD_TYPE MATCHES Debug))
927+
set(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX})
928+
endif()
929+
930+
if(PCRE2_BUILD_PCRE2_8)
931+
configure_file(libpcre2-posix.pc.in libpcre2-posix.pc @ONLY)
932+
list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-posix.pc")
933+
configure_file(libpcre2-8.pc.in libpcre2-8.pc @ONLY)
934+
list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-8.pc")
935+
set(enable_pcre2_8 "yes")
936+
else()
937+
set(enable_pcre2_8 "no")
938+
endif()
939+
940+
if(PCRE2_BUILD_PCRE2_16)
941+
configure_file(libpcre2-16.pc.in libpcre2-16.pc @ONLY)
942+
list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-16.pc")
943+
set(enable_pcre2_16 "yes")
944+
else()
945+
set(enable_pcre2_16 "no")
946+
endif()
947+
948+
if(PCRE2_BUILD_PCRE2_32)
949+
configure_file(libpcre2-32.pc.in libpcre2-32.pc @ONLY)
950+
list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-32.pc")
951+
set(enable_pcre2_32 "yes")
952+
else()
953+
set(enable_pcre2_32 "no")
954+
endif()
955+
956+
configure_file(pcre2-config.in pcre2-config @ONLY NEWLINE_STYLE LF)
957+
957958
# Executables
958959

959960
IF(PCRE2_BUILD_PCRE2GREP)
@@ -1116,7 +1117,6 @@ echo RunTest.bat tests successfully completed
11161117
ADD_TEST(pcre2posix_test pcre2posix_test)
11171118
ENDIF(PCRE2_BUILD_PCRE2_8)
11181119

1119-
11201120
ENDIF(PCRE2_BUILD_TESTS)
11211121

11221122
# Installation

0 commit comments

Comments
 (0)