diff --git a/CMakeLists.txt b/CMakeLists.txt index 4090ea75..50df8e48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 2.8) -project(picrin) +PROJECT(picrin) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") # git submodule update --init execute_process( diff --git a/README.md b/README.md index f7ae0d8d..797c28f9 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ picrin scheme depends on some external libraries to build the binary: - getopt - readline (optional) +Optional libraries are, if cmake detected them, automatically enabled. The compilation is tested only on Mac OSX and Ubuntu. I think (or hope) it'll be ok to compile and run on other operating systems such as Arch or Windows, but I don't guarantee :( ## Authors diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake new file mode 100644 index 00000000..ca0834cc --- /dev/null +++ b/cmake/FindReadline.cmake @@ -0,0 +1,86 @@ +# This file was a part of LuaJit project. + +# =============================================================================== +# LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ + +# Copyright (C) 2005-2013 Mike Pall. All rights reserved. + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# [ MIT license: http://www.opensource.org/licenses/mit-license.php ] + +# =============================================================================== +# [ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ] + +# Copyright (C) 1994-2012 Lua.org, PUC-Rio. + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# =============================================================================== +# [ LuaJIT includes code from dlmalloc, which has this license statement: ] + +# This is a version (aka dlmalloc) of malloc/free/realloc written by +# Doug Lea and released to the public domain, as explained at +# http://creativecommons.org/licenses/publicdomain + +# =============================================================================== + + + +# - Try to find Readline +# Once done this will define +# READLINE_FOUND - System has readline +# READLINE_INCLUDE_DIRS - The readline include directories +# READLINE_LIBRARIES - The libraries needed to use readline +# READLINE_DEFINITIONS - Compiler switches required for using readline + +find_package ( PkgConfig ) +pkg_check_modules ( PC_READLINE QUIET readline ) +set ( READLINE_DEFINITIONS ${PC_READLINE_CFLAGS_OTHER} ) + +find_path ( READLINE_INCLUDE_DIR readline/readline.h + HINTS ${PC_READLINE_INCLUDEDIR} ${PC_READLINE_INCLUDE_DIRS} + PATH_SUFFIXES readline ) + +find_library ( READLINE_LIBRARY NAMES readline + HINTS ${PC_READLINE_LIBDIR} ${PC_READLINE_LIBRARY_DIRS} ) + +set ( READLINE_LIBRARIES ${READLINE_LIBRARY} ) +set ( READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR} ) + +include ( FindPackageHandleStandardArgs ) +# handle the QUIETLY and REQUIRED arguments and set READLINE_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args ( readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR ) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 97619e93..ed3efbca 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,3 +1,9 @@ +find_package(READLINE) +if (READLINE_FOUND) + include_directories(${READLINE_INCLUDE_DIRS}) + add_definitions(${READLINE_DEFINITIONS} -DPIC_ENABLE_READLINE=1) +endif() + add_executable(repl tools/main.c) set_target_properties(repl PROPERTIES OUTPUT_NAME picrin) -target_link_libraries(repl picrin readline) +target_link_libraries(repl picrin ${READLINE_LIBRARIES})