Commit f932a178 authored by Johan Ström's avatar Johan Ström

Proper python installation detection, slight cmake cleanup

parent 1d090ef9
......@@ -4,12 +4,17 @@ project (agocontrol)
# The version number.
set (AGOCONTROL_VERSION 0.1)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(PkgConfig REQUIRED)
include (CheckIncludeFiles)
include(cmake/AgoFileHelpers.cmake)
find_package(PythonNaive)
# FreeBSD have some differences in building, mainly
# that non-base libs/includes are located in /usr/local.
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
......@@ -51,15 +56,11 @@ ELSE (FREEBSD)
set (LOCALSTATEDIR /var/opt/agocontrol CACHE STRING "Directory for state info")
set (HTMLDIR ${BASEDIR}/html CACHE STRING "Directory for rpc HTML files")
set (AUGEASLENSEDIR /usr/share/augeas/lenses CACHE STRING "Directory for augeas lenses")
set (PYTHON2DIST /usr/lib/python2.7/dist-packages CACHE STRING "Directory for Python 2.7 packages")
set (PYTHON3DIST /usr/lib/python3/dist-packages CACHE STRING "Directory for Python 3 packages")
set (CMAKE_EXE_LINKER_FLAGS "-Wl,-z,now")
ENDIF (FREEBSD)
set_property( DIRECTORY
APPEND PROPERTY
COMPILE_OPTIONS
-Wall -DBOOST_LOG_DYN_LINK)
set (PYTHON2DIST ${LOCALDIR}/${Python2_SITELIB} CACHE STRING "Directory for Python 2.7 packages")
set (PYTHON3DIST ${LOCALDIR}/${Python3_SITELIB} CACHE STRING "Directory for Python 3 packages")
# Enable C++11
if (CMAKE_VERSION VERSION_LESS "3.1")
......@@ -72,21 +73,19 @@ else ()
set (CMAKE_CXX_STANDARD 11)
endif ()
set_property( DIRECTORY
APPEND PROPERTY
COMPILE_OPTIONS
-Wall
-DBOOST_LOG_DYN_LINK
-DBOOST_FILESYSTEM_VERSION=3
-DBOOST_FILESYSTEM_NO_DEPRECATED
)
# Workaround for bug in Boost on Clang which tries to add pragma warning group keyward-warning
# which does not exists in clang:
# http://lists.boost.org/Archives/boost/2016/07/230350.php
set_property( DIRECTORY
APPEND PROPERTY
COMPILE_OPTIONS
-Wno-error=unknown-pragmas)
# Workaround for bug in Boost on Clang which tries to add pragma warning group keyward-warning
# which does not exists in clang:
# http://lists.boost.org/Archives/boost/2016/07/230350.php
-Wno-error=unknown-pragmas
)
# add the binary tree to the search path for include files
# so that we will find version.h and other configured files
......@@ -100,7 +99,6 @@ include_directories("${PROJECT_SOURCE_DIR}/shared/jsoncpp")
# fix augeas bug
include_directories("${LOCALDIR}/include/libxml2")
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(CppDb REQUIRED)
if (CPPDB_FOUND)
......
# On modern CMake versions we have https://cmake.org/cmake/help/latest/module/FindPython2.html etc
# but on cmake 3.0 we don't.
# This is losely based on https://github.com/caffe2/caffe2/issues/1676
function(pycmd python_exe outvar cmd)
# run the actual command
execute_process(
COMMAND "${python_exe}" -c "${cmd}"
RESULT_VARIABLE _exitcode
OUTPUT_VARIABLE _output)
if(NOT ${_exitcode} EQUAL 0)
message(ERROR " Failed when running ${python_exe} code: \"\"\"\n${cmd}\n\"\"\"")
message(FATAL_ERROR " Python command failed with error code: ${_exitcode}")
endif()
# Remove supurflous newlines (artifacts of print)
string(STRIP "${_output}" _output)
set(${outvar} "${_output}" PARENT_SCOPE)
endfunction()
find_program(PYTHON2_EXECUTABLE NAMES python2 python2.7 python2.6)
find_program(PYTHON3_EXECUTABLE NAMES python3)
if(PYTHON2_EXECUTABLE)
pycmd(${PYTHON2_EXECUTABLE} Python2_SITELIB "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(prefix='')")
message(STATUS "Python2_SITELIB = ${Python2_SITELIB}")
else()
message(ERROR "python2 executable not found. this is required for proper agocontrol operation")
endif()
if(PYTHON3_EXECUTABLE)
pycmd(${PYTHON3_EXECUTABLE} Python3_SITELIB "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(prefix=''))")
message(STATUS "Python3_SITELIB = ${Python3_SITELIB}")
else()
message(STATUS "python3 executable not found")
endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment