diff options
author | Johann Klähn <kljohann@gmail.com> | 2013-10-23 23:08:18 +0200 |
---|---|---|
committer | Johann Klähn <kljohann@gmail.com> | 2014-02-01 01:30:53 +0100 |
commit | 89c21e9967cec214597044aa582741470404977c (patch) | |
tree | f54c388e606e5f9296f991cae64678bdbaf0a8b2 | |
parent | 35c1bf03eca615ee747162c356c74ba280a6d03c (diff) | |
download | fork-ledger-89c21e9967cec214597044aa582741470404977c.tar.gz fork-ledger-89c21e9967cec214597044aa582741470404977c.tar.bz2 fork-ledger-89c21e9967cec214597044aa582741470404977c.zip |
build shared library/python module, clean up CMake
libledger will now be built as a shared library. You can 'import ledger'
from python IFF you copy libledger.so to ledger.so or create a symlink.
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/CMakeLists.txt | 48 | ||||
-rw-r--r-- | test/unit/CMakeLists.txt | 2 |
3 files changed, 38 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fc2ef2bb..4cd56027 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,10 @@ endif() find_package(PythonInterp) # Used for running tests if(USE_PYTHON) + if(NOT BUILD_LIBRARY) + message(ERROR "Building the python module requires BUILD_LIBRARY=ON.") + endif() + set(Python_ADDITIONAL_VERSIONS 2.7 2.6) find_package(PythonLibs) if(PYTHONLIBS_FOUND) @@ -232,9 +236,6 @@ find_opt_library_and_header(EDIT_PATH histedit.h EDIT_LIB edit HAVE_EDIT) ######################################################################## macro(add_ledger_library_dependencies _target) - if(BUILD_LIBRARY) - target_link_libraries(${_target} libledger) - endif() target_link_libraries(${_target} ${MPFR_LIB}) target_link_libraries(${_target} ${GMP_LIB}) if(HAVE_EDIT) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c6a9e28e..06d12bac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -163,6 +163,9 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(_args ${CMAKE_CXX_FLAGS}) list(APPEND _args ${CMAKE_CXX_FLAGS_DEBUG}) + if(BUILD_LIBRARY) + list(APPEND _args ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + endif() list(APPEND _args "-x c++-header " ${_inc}) list(APPEND _args -c ${_header_filename} -o ${_pch_filename}) @@ -215,6 +218,9 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(_args ${CMAKE_CXX_FLAGS}) list(APPEND _args ${CMAKE_CXX_FLAGS_DEBUG}) + if(BUILD_LIBRARY) + list(APPEND _args ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + endif() list(APPEND _args ${GXX_WARNING_FLAGS}) list(APPEND _args "-x c++-header " ${_inc}) list(APPEND _args -c ${_header_filename} -o ${_gch_filename}) @@ -243,30 +249,42 @@ endif() add_pch_rule(${PROJECT_BINARY_DIR}/system.hh LEDGER_SOURCES main.cc global.cc) -if(BUILD_LIBRARY) - add_library(pyledger SHARED ${LEDGER_SOURCES}) - add_ledger_library_dependencies(pyledger) - if(CMAKE_HOST_APPLE) - set_target_properties(pyledger PROPERTIES OUTPUT_NAME ledger) - set_target_properties(pyledger PROPERTIES SUFFIX .so) - set(CMAKE_SHARED_LIBRARY_PREFIX ) - endif() +include(GNUInstallDirs) - add_library(libledger ${LEDGER_SOURCES} ${PROJECT_SOURCE_DIR}/lib/sha1.cpp) - set_target_properties(libledger PROPERTIES OUTPUT_NAME ledger) +if(BUILD_LIBRARY) + add_library(libledger SHARED ${LEDGER_SOURCES} ${PROJECT_SOURCE_DIR}/lib/sha1.cpp) + add_ledger_library_dependencies(libledger) + set_property(TARGET libledger PROPERTY PREFIX "") add_executable(ledger main.cc global.cc) + target_link_libraries(ledger libledger) - install(TARGETS pyledger DESTINATION lib) - install(TARGETS libledger DESTINATION lib) - install(FILES ${LEDGER_INCLUDES} DESTINATION include/ledger) + install(TARGETS libledger DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(FILES ${LEDGER_INCLUDES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ledger) else() add_executable(ledger ${LEDGER_SOURCES} ${PROJECT_SOURCE_DIR}/lib/sha1.cpp main.cc global.cc) + add_ledger_library_dependencies(ledger) endif() -add_ledger_library_dependencies(ledger) +if(USE_PYTHON) + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c + "from __future__ import print_function +import distutils.sysconfig as s +print(s.get_python_lib(True, prefix=''))" + OUTPUT_VARIABLE _TMP_PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE) + set(PYTHON_SITE_PACKAGES ${_TMP_PYTHON_SITE_PACKAGES} + CACHE PATH "python module directory (${_TMP_PYTHON_SITE_PACKAGES})") + + if (PYTHON_SITE_PACKAGES) + # FIXME: symlink would be sufficient + install(TARGETS libledger + DESTINATION ${PYTHON_SITE_PACKAGES} RENAME "ledger${CMAKE_SHARED_LIBRARY_SUFFIX}") + else() + message(WARNING "PYTHON_SITE_PACKAGES not set. Will not install python module.") + endif() +endif() -install(TARGETS ledger DESTINATION bin) +install(TARGETS ledger DESTINATION ${CMAKE_INSTALL_BINDIR}) ### CMakeLists.txt ends here diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 5ecd5a87..b3639c06 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,5 +1,5 @@ macro(add_ledger_test _name) - add_ledger_library_dependencies(${_name}) + target_link_libraries(${_name} libledger) add_test(Ledger${_name} ${PROJECT_BINARY_DIR}/${_name}) endmacro(add_ledger_test _name) |