From 36665da832cca6621b86f05fb0ff64551c114051 Mon Sep 17 00:00:00 2001 From: "Ricardo Constantino (:RiCON)" Date: Wed, 16 Mar 2016 14:17:25 +0000 Subject: [PATCH 1/7] CMake: allow installing binary to non-default dir --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f279e1..223b53f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,10 @@ set (DIR_SHARE ${DIR_PREFIX}/share) set (DIR_BIN ${DIR_PREFIX}/bin) set (DIR_ETC ${DIR_PREFIX}/etc) +if (DEFINED CMAKE_INSTALL_BINDIR) + set (DIR_BIN ${CMAKE_INSTALL_BINDIR}) +endif (DEFINED CMAKE_INSTALL_BINDIR) + if (DEFINED CMAKE_INSTALL_LIBDIR) set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR}) set (DIR_LIBRARY_STATIC ${CMAKE_INSTALL_LIBDIR}) From f53cb8cdddf96de2540995fe01df482fc53a8b45 Mon Sep 17 00:00:00 2001 From: "Ricardo Constantino (:RiCON)" Date: Wed, 16 Mar 2016 14:17:47 +0000 Subject: [PATCH 2/7] CMake: fix linking with Ninja --- src/symbols.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symbols.cmake b/src/symbols.cmake index 9453baf..bd83f1d 100644 --- a/src/symbols.cmake +++ b/src/symbols.cmake @@ -25,7 +25,7 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU) set(_version_script "${CMAKE_CURRENT_BINARY_DIR}/version.script") file(WRITE ${_version_script} "${_symbols}\n") - set(LINK_FLAGS "${LINK_FLAGS} -Wl,--version-script,'${_version_script}'") + set(LINK_FLAGS "${LINK_FLAGS} -Wl,--version-script,${_version_script}") endif (APPLE) From 6500f09931bb0f348ccc6860b43e1f5f9db6be2d Mon Sep 17 00:00:00 2001 From: "Ricardo Constantino (:RiCON)" Date: Wed, 16 Mar 2016 14:25:06 +0000 Subject: [PATCH 3/7] CMake: Allow building static-only builds Add stdc++ to static libs in pkg-config --- CMakeLists.txt | 6 +++++- src/CMakeLists.txt | 1 - uchardet.pc.in | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 223b53f..325f763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,8 +63,12 @@ set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale) ######## Configuration -option(BUILD_STATIC "Build static library" +option(BUILD_SHARED_LIBS "Build shared library and link executable against it" ON) +if (BUILD_SHARED_LIBS) + option(BUILD_STATIC "Build static library" + ON) +endif (BUILD_SHARED_LIBS) configure_file( uchardet.pc.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39f460c..32e62c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,7 +54,6 @@ add_definitions( add_library( ${UCHARDET_TARGET} - SHARED ${UCHARDET_SOURCES} ) diff --git a/uchardet.pc.in b/uchardet.pc.in index 660a401..8f646fd 100644 --- a/uchardet.pc.in +++ b/uchardet.pc.in @@ -8,4 +8,5 @@ Description: An encoding detector library ported from Mozilla Version: @UCHARDET_VERSION@ Requires: Libs: -L${libdir} -luchardet +Libs.private: -lstdc++ Cflags: -I${includedir}/uchardet From 50b2e0802f1036cbba3099de93307f4cb9dd846c Mon Sep 17 00:00:00 2001 From: "Ricardo Constantino (:RiCON)" Date: Wed, 16 Mar 2016 14:34:03 +0000 Subject: [PATCH 4/7] CMake: Allow not building executable --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 325f763..b53420d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,8 @@ if (BUILD_SHARED_LIBS) option(BUILD_STATIC "Build static library" ON) endif (BUILD_SHARED_LIBS) +option(BUILD_BINARY "Build executable" + ON) configure_file( uchardet.pc.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32e62c2..e50ae50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,4 +132,6 @@ install( include(symbols.cmake) +if (BUILD_BINARY) add_subdirectory(tools) +endif (BUILD_BINARY) From 81ed86a26b37b55e5f8c72b85e6aec06eb86130c Mon Sep 17 00:00:00 2001 From: "Ricardo Constantino (:RiCON)" Date: Wed, 16 Mar 2016 18:47:14 +0000 Subject: [PATCH 5/7] CMake: Use only CMAKE_INSTALL_BINDIR instead of DIR_BIN This way it always shows up in ccmake, even if not defined. A string is used instead of path because I personally think it makes more sense in the following use-cases: STRING: -DCMAKE_INSTALL_PREFIX=/home/user -DCMAKE_INSTALL_BINDIR=bins installs everything to /home/user/{lib,etc,share,(...)} and executables to ${CMAKE_INSTALL_PREFIX}/bins -DCMAKE_INSTALL_PREFIX=/home/user -DCMAKE_INSTALL_BINDIR=/opt/bin everything to /home/user/{lib,etc,share,(...)} and executables to /opt/bin PATH: -DCMAKE_INSTALL_PREFIX=/home/user -DCMAKE_INSTALL_BINDIR=bins everything to /home/user/{lib,etc,share,(...)} and executables to $(pwd)/bins (!) -DCMAKE_INSTALL_PREFIX=/home/user -DCMAKE_INSTALL_BINDIR=/opt/bin same as STRING --- CMakeLists.txt | 6 ++---- src/CMakeLists.txt | 2 +- src/tools/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b53420d..2909b30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,12 +34,10 @@ set (DIR_LIBRARY ${DIR_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX}) set (DIR_LIBRARY_STATIC ${DIR_PREFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}) set (DIR_INCLUDE ${DIR_PREFIX}/include) set (DIR_SHARE ${DIR_PREFIX}/share) -set (DIR_BIN ${DIR_PREFIX}/bin) set (DIR_ETC ${DIR_PREFIX}/etc) -if (DEFINED CMAKE_INSTALL_BINDIR) - set (DIR_BIN ${CMAKE_INSTALL_BINDIR}) -endif (DEFINED CMAKE_INSTALL_BINDIR) +set (CMAKE_INSTALL_BINDIR bin + CACHE STRING "Install location of executables") if (DEFINED CMAKE_INSTALL_LIBDIR) set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e50ae50..9a66412 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,7 +108,7 @@ install( TARGETS ${UCHARDET_TARGET} RUNTIME DESTINATION - ${DIR_BIN} + ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${DIR_LIBRARY} ) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 7ad3ff5..a2ddf94 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -18,6 +18,6 @@ install( uchardet RUNTIME DESTINATION - ${DIR_BIN} + ${CMAKE_INSTALL_BINDIR} ) From b908b689a02f017ea8804f24968e924d2e922f72 Mon Sep 17 00:00:00 2001 From: "Ricardo Constantino (:RiCON)" Date: Wed, 16 Mar 2016 18:51:15 +0000 Subject: [PATCH 6/7] CMake: Add static lib destination to UCHARDET_TARGET --- src/CMakeLists.txt | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a66412..1278f5f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,19 +98,21 @@ endif (CMAKE_BUILD_TYPE MATCHES Debug) if (NOT WIN32) install( - TARGETS - ${UCHARDET_TARGET} - LIBRARY DESTINATION - ${DIR_LIBRARY} + TARGETS + ${UCHARDET_TARGET} + LIBRARY DESTINATION + ${DIR_LIBRARY} + ARCHIVE DESTINATION + ${DIR_LIBRARY} ) else (NOT WIN32) install( - TARGETS - ${UCHARDET_TARGET} - RUNTIME DESTINATION - ${CMAKE_INSTALL_BINDIR} - ARCHIVE DESTINATION - ${DIR_LIBRARY} + TARGETS + ${UCHARDET_TARGET} + RUNTIME DESTINATION + ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION + ${DIR_LIBRARY} ) endif (NOT WIN32) From 86755b1f574a40ea7ffd26dae2d5b330157fc6aa Mon Sep 17 00:00:00 2001 From: "Ricardo Constantino (:RiCON)" Date: Wed, 16 Mar 2016 19:08:47 +0000 Subject: [PATCH 7/7] CMake: Don't build static more than once --- src/CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1278f5f..a48f029 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,7 +42,9 @@ set( ) set (UCHARDET_TARGET libuchardet) +if (BUILD_STATIC AND BUILD_SHARED_LIBS) set (UCHARDET_STATIC_TARGET libuchardet_static) +endif () add_definitions( -DPKGDATADIR="${DIR_SHARE_OPENCC}" @@ -57,13 +59,13 @@ add_library( ${UCHARDET_SOURCES} ) -if (BUILD_STATIC) +if (UCHARDET_STATIC_TARGET) add_library( ${UCHARDET_STATIC_TARGET} STATIC ${UCHARDET_SOURCES} ) -endif (BUILD_STATIC) +endif (UCHARDET_STATIC_TARGET) set_target_properties( ${UCHARDET_TARGET} @@ -78,7 +80,7 @@ set_target_properties( 0 ) -if (BUILD_STATIC) +if (UCHARDET_STATIC_TARGET) set_target_properties( ${UCHARDET_STATIC_TARGET} PROPERTIES @@ -87,7 +89,7 @@ if (BUILD_STATIC) OUTPUT_NAME uchardet ) -endif (BUILD_STATIC) +endif (UCHARDET_STATIC_TARGET) if (CMAKE_BUILD_TYPE MATCHES Debug) add_definitions( @@ -116,14 +118,14 @@ install( ) endif (NOT WIN32) -if (BUILD_STATIC) +if (UCHARDET_STATIC_TARGET) install( TARGETS ${UCHARDET_STATIC_TARGET} ARCHIVE DESTINATION ${DIR_LIBRARY_STATIC} ) -endif (BUILD_STATIC) +endif (UCHARDET_STATIC_TARGET) install( FILES