summaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
diff options
context:
space:
mode:
authorJohann Klähn <kljohann@gmail.com>2013-10-23 23:08:18 +0200
committerJohann Klähn <kljohann@gmail.com>2014-02-01 01:30:53 +0100
commit89c21e9967cec214597044aa582741470404977c (patch)
treef54c388e606e5f9296f991cae64678bdbaf0a8b2 /src/CMakeLists.txt
parent35c1bf03eca615ee747162c356c74ba280a6d03c (diff)
downloadfork-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.
Diffstat (limited to 'src/CMakeLists.txt')
-rw-r--r--src/CMakeLists.txt48
1 files changed, 33 insertions, 15 deletions
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