Add pkg-config support

Closes #1032
This commit is contained in:
Martin Hořeňovský 2017-10-12 21:42:09 +02:00
parent 355ab78f4a
commit c7d9f02d5b
3 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,7 @@ set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest) set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark) set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
set(HEADER_DIR ${CATCH_DIR}/include) set(HEADER_DIR ${CATCH_DIR}/include)
set(CATCH_VERSION_NUMBER 2.0.0)
if(USE_CPP14) if(USE_CPP14)
message(STATUS "Enabling C++14") message(STATUS "Enabling C++14")
@ -331,3 +332,17 @@ endif() # !NO_SELFTEST
install(DIRECTORY "single_include/" DESTINATION "include/catch") install(DIRECTORY "single_include/" DESTINATION "include/catch")
## Provide some pkg-config integration
# Don't bother on Windows
if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
set(PKGCONFIG_INSTALL_DIR
"${CMAKE_INSTALL_PREFIX}/share/pkgconfig"
CACHE PATH "Path where catch.pc is installed"
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/catch.pc.in ${CMAKE_CURRENT_BINARY_DIR}/catch.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/catch.pc DESTINATION ${PKGCONFIG_INSTALL_DIR})
endif()

10
catch.pc.in Normal file
View File

@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
Name: Catch
Description: Testing library for C++
Requires:
Version: @CATCH_VERSION_NUMBER@
Libs:
Cflags: -I${prefix}/@INCLUDE_INSTALL_DIR@

View File

@ -15,6 +15,7 @@ versionPath = os.path.join( rootPath, "internal/catch_version.cpp" )
readmePath = os.path.join( catchPath, "README.md" ) readmePath = os.path.join( catchPath, "README.md" )
conanPath = os.path.join(catchPath, 'conanfile.py') conanPath = os.path.join(catchPath, 'conanfile.py')
conanTestPath = os.path.join(catchPath, 'test_package', 'conanfile.py') conanTestPath = os.path.join(catchPath, 'test_package', 'conanfile.py')
cmakePath = os.path.join(catchPath, 'CMakeLists.txt')
class Version: class Version:
def __init__(self): def __init__(self):
@ -126,6 +127,17 @@ def updateConanTestFile(version):
for line in lines: for line in lines:
f.write( line + "\n" ) f.write( line + "\n" )
def updateCmakeFile(version):
cmakeParser = re.compile(r'set(CATCH_VERSION_NUMBER \d+\.\d+\.\d+)')
with open(cmakePath, 'r') as file:
lines = file.readlines()
with open(cmakePath, 'w') as file:
for line in lines:
if 'set(CATCH_VERSION_NUMBER ' in line:
file.write('set(CATCH_VERSION_NUMBER {0})\n'.format(version.getVersionString()))
else:
file.write(line)
def performUpdates(version): def performUpdates(version):
# First update version file, so we can regenerate single header and # First update version file, so we can regenerate single header and
# have it ready for upload to wandbox, when updating readme # have it ready for upload to wandbox, when updating readme
@ -134,3 +146,4 @@ def performUpdates(version):
updateReadmeFile(version) updateReadmeFile(version)
updateConanFile(version) updateConanFile(version)
updateConanTestFile(version) updateConanTestFile(version)
updateCmakeFile(version)