From d6a60dbd37f7d043d7d568832d59528ac28cc0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Fri, 20 Oct 2023 12:25:54 -0700 Subject: [PATCH] cmake: set PCRE2POSIX_CFLAG in pcre2-config and pkg-config 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. --- CMakeLists.txt | 84 +++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d86a33d14..e706ed4a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -573,46 +573,6 @@ IF(WIN32) SET(CMAKE_DEBUG_POSTFIX "d") ENDIF(WIN32) -# Generate pkg-config files - -SET(PACKAGE_VERSION "${PCRE2_MAJOR}.${PCRE2_MINOR}") -SET(prefix ${CMAKE_INSTALL_PREFIX}) - -SET(exec_prefix "\${prefix}") -SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") -SET(includedir "\${prefix}/include") -IF(WIN32 AND (CMAKE_BUILD_TYPE MATCHES Debug)) - SET(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -ENDIF() -CONFIGURE_FILE(libpcre2-posix.pc.in libpcre2-posix.pc @ONLY) -SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-posix.pc") - -IF(PCRE2_BUILD_PCRE2_8) - CONFIGURE_FILE(libpcre2-8.pc.in libpcre2-8.pc @ONLY) - SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-8.pc") - SET(enable_pcre2_8 "yes") -ELSE() - SET(enable_pcre2_8 "no") -ENDIF() - -IF(PCRE2_BUILD_PCRE2_16) - CONFIGURE_FILE(libpcre2-16.pc.in libpcre2-16.pc @ONLY) - SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-16.pc") - SET(enable_pcre2_16 "yes") -ELSE() - SET(enable_pcre2_16 "no") -ENDIF() - -IF(PCRE2_BUILD_PCRE2_32) - CONFIGURE_FILE(libpcre2-32.pc.in libpcre2-32.pc @ONLY) - SET(pkg_config_files ${pkg_config_files} "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-32.pc") - SET(enable_pcre2_32 "yes") -ELSE() - SET(enable_pcre2_32 "no") -ENDIF() - -CONFIGURE_FILE(pcre2-config.in pcre2-config @ONLY) - # Character table generation OPTION(PCRE2_REBUILD_CHARTABLES "Rebuild char tables" OFF) @@ -797,7 +757,8 @@ IF(PCRE2_BUILD_PCRE2_8) VERSION ${LIBPCRE2_POSIX_VERSION} SOVERSION ${LIBPCRE2_POSIX_SOVERSION} OUTPUT_NAME pcre2-posix) - TARGET_COMPILE_DEFINITIONS(pcre2-posix-shared PUBLIC PCRE2POSIX_SHARED) + set(PCRE2POSIX_CFLAG "-DPCRE2POSIX_SHARED") + TARGET_COMPILE_DEFINITIONS(pcre2-posix-shared PUBLIC ${PCRE2POSIX_CFLAG}) TARGET_LINK_LIBRARIES(pcre2-posix-shared pcre2-8-shared) SET(targets ${targets} pcre2-posix-shared) SET(dll_pdb_files ${PROJECT_BINARY_DIR}/pcre2-8.pdb ${dll_pdb_files}) @@ -954,6 +915,46 @@ IF(PCRE2_BUILD_PCRE2_32) ENDIF(BUILD_STATIC_LIBS) ENDIF(PCRE2_BUILD_PCRE2_32) +# Generate pkg-config files + +set(PACKAGE_VERSION "${PCRE2_MAJOR}.${PCRE2_MINOR}") +set(prefix ${CMAKE_INSTALL_PREFIX}) + +set(exec_prefix "\${prefix}") +set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") +set(includedir "\${prefix}/include") +if(WIN32 AND (CMAKE_BUILD_TYPE MATCHES Debug)) + set(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX}) +endif() + +if(PCRE2_BUILD_PCRE2_8) + configure_file(libpcre2-posix.pc.in libpcre2-posix.pc @ONLY) + list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-posix.pc") + configure_file(libpcre2-8.pc.in libpcre2-8.pc @ONLY) + list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-8.pc") + set(enable_pcre2_8 "yes") +else() + set(enable_pcre2_8 "no") +endif() + +if(PCRE2_BUILD_PCRE2_16) + configure_file(libpcre2-16.pc.in libpcre2-16.pc @ONLY) + list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-16.pc") + set(enable_pcre2_16 "yes") +else() + set(enable_pcre2_16 "no") +endif() + +if(PCRE2_BUILD_PCRE2_32) + configure_file(libpcre2-32.pc.in libpcre2-32.pc @ONLY) + list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-32.pc") + set(enable_pcre2_32 "yes") +else() + set(enable_pcre2_32 "no") +endif() + +configure_file(pcre2-config.in pcre2-config @ONLY NEWLINE_STYLE LF) + # Executables IF(PCRE2_BUILD_PCRE2GREP) @@ -1116,7 +1117,6 @@ echo RunTest.bat tests successfully completed ADD_TEST(pcre2posix_test pcre2posix_test) ENDIF(PCRE2_BUILD_PCRE2_8) - ENDIF(PCRE2_BUILD_TESTS) # Installation