Skip to content

Commit

Permalink
build: duktape CMake scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Mar 29, 2024
1 parent 313abfb commit 586ce9b
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 6 deletions.
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ llvm_map_components_to_libnames(llvm_libs all)
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

# fmt
find_package(fmt REQUIRED CONFIG)

# Duktape
set(DUKTAPE_PACKAGE_NAME duktape)
if (WIN32)
set(DUKTAPE_PACKAGE_NAME Duktape)
find_package(duktape CONFIG)
if (NOT DUKTAPE_FOUND)
# Duktape doesn't nativelly support CMake.
# Some config script patches use the capitalized version.
find_package(Duktape REQUIRED CONFIG)
endif()
find_package(${DUKTAPE_PACKAGE_NAME} REQUIRED)

# fmt
find_package(fmt REQUIRED CONFIG)
unset(CMAKE_FOLDER)

#-------------------------------------------------
Expand Down
70 changes: 70 additions & 0 deletions third-party/duktape/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Copyright (c) 2024 Alan de Freitas ([email protected])
#
# Official repository: https://github.com/cppalliance/mrdocs
#
#

#
# This file is derived from the CMakeLists.txt file in the Microsoft vcpkg repository:
# https://github.com/microsoft/vcpkg/blob/master/ports/duktape/CMakeLists.txt
#

cmake_minimum_required(VERSION 3.13)

set(duktape_MAJOR_VERSION 2)
set(duktape_MINOR_VERSION 7)
set(duktape_PATCH_VERSION 0)
set(duktape_VERSION ${duktape_MAJOR_VERSION}.${duktape_MINOR_VERSION}.${duktape_PATCH_VERSION})

option(CMAKE_VERBOSE_MAKEFILE "Create verbose makefile" OFF)
option(BUILD_SHARED_LIBS "Create duktape as a shared library" OFF)

project(duktape VERSION ${duktape_VERSION})

file(GLOB_RECURSE DUKTAPE_SOURCES "${CMAKE_CURRENT_LIST_DIR}/src/*.c")
file(GLOB_RECURSE DUKTAPE_HEADERS "${CMAKE_CURRENT_LIST_DIR}/src/*.h")

add_library(duktape ${DUKTAPE_SOURCES} ${DUKTAPE_HEADERS})
target_include_directories(duktape PRIVATE "${CMAKE_CURRENT_LIST_DIR}/src")
set_target_properties(duktape PROPERTIES PUBLIC_HEADER "${DUKTAPE_HEADERS}")
set_target_properties(duktape PROPERTIES VERSION ${duktape_VERSION})
set_target_properties(duktape PROPERTIES SOVERSION ${duktape_MAJOR_VERSION})

if (BUILD_SHARED_LIBS)
target_compile_definitions(duktape PRIVATE -DDUK_F_DLL_BUILD)
endif ()

install(TARGETS duktape
EXPORT duktapeTargets
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin"
PUBLIC_HEADER DESTINATION "include"
COMPONENT dev
)

install(EXPORT duktapeTargets
FILE duktapeTargets.cmake
NAMESPACE duktape::
DESTINATION "share/duktape"
)

export(PACKAGE duktape)

include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/duktapeConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)

configure_file(duktapeConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/duktapeConfig.cmake" @ONLY)

install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/duktapeConfig.cmake"
"${PROJECT_BINARY_DIR}/duktapeConfigVersion.cmake"
DESTINATION "share/duktape"
)
48 changes: 48 additions & 0 deletions third-party/duktape/duktapeConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Copyright (c) 2024 Alan de Freitas ([email protected])
#
# Official repository: https://github.com/cppalliance/mrdocs
#
#

#
# This file is derived from the CMakeLists.txt file in the Microsoft vcpkg repository:
# https://github.com/microsoft/vcpkg/blob/master/ports/duktape/CMakeLists.txt
#

# - Try to find duktape
# Once done this will define
#
# DUKTAPE_FOUND - system has Duktape
# DUKTAPE_INCLUDE_DIRS - the Duktape include directory
# DUKTAPE_LIBRARIES - Link these to use DUKTAPE
# DUKTAPE_DEFINITIONS - Compiler switches required for using Duktape
#

find_package(PkgConfig QUIET)
pkg_check_modules(PC_DUK QUIET duktape libduktape)

find_path(DUKTAPE_INCLUDE_DIR duktape.h
HINTS ${duktape_ROOT}/include ${PC_DUK_INCLUDEDIR} ${PC_DUK_INCLUDE_DIRS}
PATH_SUFFIXES duktape)

find_library(DUKTAPE_LIBRARY
NAMES duktape libduktape
HINTS ${duktape_ROOT}/lib ${duktape_ROOT}/bin ${PC_DUK_LIBDIR} ${PC_DUK_LIBRARY_DIRS})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(duktape REQUIRED_VARS DUKTAPE_LIBRARY DUKTAPE_INCLUDE_DIR)

if (DUKTAPE_FOUND)
set(DUKTAPE_LIBRARIES ${DUKTAPE_LIBRARY})
set(DUKTAPE_INCLUDE_DIRS ${DUKTAPE_INCLUDE_DIR})
endif ()

MARK_AS_ADVANCED(
DUKTAPE_INCLUDE_DIR
DUKTAPE_LIBRARY
)

0 comments on commit 586ce9b

Please sign in to comment.