Hi,

Inspired by Timofei's work on the cmake branch, I checked it out and tried
to build on Linux.

It worked, almost.

[[[
[ 17%] Building C object
CMakeFiles/libsvn_subr.dir/subversion/libsvn_subr/sysinfo.c.o
/home/dsg/svn_cmake/subversion/libsvn_subr/sysinfo.c: In function
‘linux_release_name’:
/home/dsg/svn_cmake/subversion/libsvn_subr/sysinfo.c:649:31: warning:
implicit declaration of function ‘release_name_from_uname’
[-Wimplicit-function-declaration]
  649 |   const char *uname_release = release_name_from_uname(pool);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~
/home/dsg/svn_cmake/subversion/libsvn_subr/sysinfo.c:649:31: warning:
initialization of ‘const char *’ from ‘int’ makes pointer from integer
without a cast [-Wint-conversion]
/home/dsg/svn_cmake/subversion/libsvn_subr/sysinfo.c: In function
‘linux_shared_libs’:
/home/dsg/svn_cmake/subversion/libsvn_subr/sysinfo.c:750:65: warning:
implicit declaration of function ‘getpid’ [-Wimplicit-function-declaration]
  750 |   const char *maps = apr_psprintf(pool, "/proc/%ld/maps",
(long)getpid());
      |
 ^~~~~~
]]]

The above warnings were caused by missing defines HAVE_SYS_UTSNAME_H,
HAVE_UNAME and HAVE_UNISTD_H.

I also got the following error:
[[[
[ 64%] Linking C shared library liblibsvn_ra-1.so
/usr/bin/ld: liblibsvn_ra_svn.a(marshal.c.o): warning: relocation against
`svn_ctype_table' in read-only section `.text'
/usr/bin/ld: liblibsvn_ra_svn.a(client.c.o): relocation R_X86_64_PC32
against symbol `svn_ctype_table' can not be used when making a shared
object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/libsvn_ra.dir/build.make:186: liblibsvn_ra-1.so]
Error 1
gmake[1]: *** [CMakeFiles/Makefile2:330: CMakeFiles/libsvn_ra.dir/all]
Error 2
gmake: *** [Makefile:136: all] Error 2
]]]

I made some effort trying to figure out the proper way to fix this and I
came up with the following changes. After this the build succeeds and I get
a working svn binary.

I'm SURE this doesn't follow CMake best-practice but I'd be happy if it
could be a starting point in getting CMake to work under Linux. I'd also be
happy to see how it SHOULD be done :-)

To get this to work under Macos, someone should look at the
SVN_HAVE_MACOS_PLIST define.

[[[
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt      (revision 1919275)
+++ CMakeLists.txt      (working copy)
@@ -125,8 +125,29 @@
   enable_testing()
 endif()

+include(CheckSymbolExists)
+include(CheckIncludeFiles)
+check_include_files("sys/utsname.h" HAVE_SYS_UTSNAME_H)
+if (HAVE_SYS_UTSNAME_H)
+  add_compile_definitions(HAVE_SYS_UTSNAME_H)
+
+  check_symbol_exists(uname sys/utsname.h HAVE_UNAME)
+  if (HAVE_UNAME)
+    add_compile_definitions(HAVE_UNAME)
+  endif()
+endif()
+check_include_files("unistd.h" HAVE_UNISTD_H)
+if (HAVE_UNISTD_H)
+  add_compile_definitions(HAVE_UNISTD_H)
+endif()
+
+if (BUILD_SHARED_LIBS)
+  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+endif()
+
 if(SVN_BUILD_SHARED_FS)
   set(SVN_FS_BUILD_TYPE SHARED)
+  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 else()
   set(SVN_FS_BUILD_TYPE STATIC)
 endif()
@@ -133,6 +154,7 @@

 if(SVN_BUILD_SHARED_RA)
   set(SVN_RA_BUILD_TYPE SHARED)
+  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 else()
   set(SVN_RA_BUILD_TYPE STATIC)
 endif()
]]]

Reply via email to