Browse Source

Merge pull request #611 from libtom/fix-mpi-pkgconfig

update `Libs` part of pkg-config file with configured MPI providers
Steffen Jaeckel 2 years ago
parent
commit
a2245e8696
3 changed files with 36 additions and 3 deletions
  1. 19 0
      CMakeLists.txt
  2. 2 2
      libtomcrypt.pc.in
  3. 15 1
      makefile.shared

+ 19 - 0
CMakeLists.txt

@@ -33,6 +33,7 @@ include(sources.cmake)
 # Options
 #-----------------------------------------------------------------------------
 option(WITH_LTM "Build with support for libtommath" TRUE)
+option(WITH_TFM "Build with support for tomsfastmath" FALSE)
 option(WITH_GMP "Build with support for GNU Multi Precision Arithmetic Library" FALSE)
 set(MPI_PROVIDER "LTM" CACHE STRING "Build tests and demos against 'LTM', 'TFM' or 'GMP', default is LTM")
 option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF)
@@ -136,6 +137,20 @@ if(WITH_LTM)
         target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM)
     endif()
     target_link_libraries(${PROJECT_NAME} PUBLIC libtommath)
+    list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DLTM_DESC)
+    list(APPEND LTC_MPI_PROVIDERS_LIBS -ltommath)
+endif()
+# tomsfastmath
+if(WITH_TFM)
+    find_package(tomsfastmath 0.13.1 REQUIRED)
+
+    target_compile_definitions(${PROJECT_NAME} PUBLIC TFM_DESC)
+    if(MPI_PROVIDER MATCHES "TFM")
+        target_compile_definitions(${PROJECT_NAME} PUBLIC USE_TFM)
+    endif()
+    target_link_libraries(${PROJECT_NAME} PUBLIC tomsfastmath)
+    list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DTFM_DESC)
+    list(APPEND LTC_MPI_PROVIDERS_LIBS -ltfm)
 endif()
 # GNU MP
 if(WITH_GMP)
@@ -146,8 +161,12 @@ if(WITH_GMP)
         target_compile_definitions(${PROJECT_NAME} PUBLIC USE_GMP)
     endif()
     target_link_libraries(${PROJECT_NAME} PUBLIC ${GMP_LIBRARIES})
+    list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DGMP_DESC)
+    list(APPEND LTC_MPI_PROVIDERS_LIBS -lgmp)
 endif()
 
+list(JOIN LTC_MPI_PROVIDERS_CFLAGS " " MPI_PROVIDERS_CFLAGS)
+list(JOIN LTC_MPI_PROVIDERS_LIBS " " MPI_PROVIDERS_LIBS)
 
 #-----------------------------------------------------------------------------
 # demos&test targets

+ 2 - 2
libtomcrypt.pc.in

@@ -6,5 +6,5 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@
 Name: LibTomCrypt
 Description: public domain open source cryptographic toolkit
 Version: @PROJECT_VERSION@
-Libs: -L${libdir} -ltomcrypt
-Cflags: -I${includedir}
+Libs: -L${libdir} -ltomcrypt @MPI_PROVIDERS_LIBS@
+Cflags: -I${includedir} @MPI_PROVIDERS_CFLAGS@

+ 15 - 1
makefile.shared

@@ -54,6 +54,18 @@ endif
 
 include makefile_include.mk
 
+ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),)
+LTC_MPI_PROVIDERS_CFLAGS += -DLTM_DESC
+LTC_MPI_PROVIDERS_LIBS += -ltommath
+endif
+ifneq ($(findstring -DTFM_DESC,$(LTC_CFLAGS)),)
+LTC_MPI_PROVIDERS_CFLAGS += -DTFM_DESC
+LTC_MPI_PROVIDERS_LIBS += -ltfm
+endif
+ifneq ($(findstring -DGMP_DESC,$(LTC_CFLAGS)),)
+LTC_MPI_PROVIDERS_CFLAGS += -DGMP_DESC
+LTC_MPI_PROVIDERS_LIBS += -lgmp
+endif
 
 #ciphers come in two flavours... enc+dec and enc
 src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
@@ -80,7 +92,9 @@ $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
 
 install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install
 	sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,@CMAKE_INSTALL_LIBDIR@,lib,' \
-		-e 's,@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@,include/tomcrypt,' libtomcrypt.pc.in > libtomcrypt.pc
+		-e 's,@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@,include/tomcrypt,' \
+		-e 's,@MPI_PROVIDERS_LIBS@,$(LTC_MPI_PROVIDERS_LIBS),' \
+		-e 's,@MPI_PROVIDERS_CFLAGS@,$(LTC_MPI_PROVIDERS_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc
 	install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig
 	install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/