Skip to content

Commit

Permalink
Merge pull request #264 from lanodan/pkgconfig
Browse files Browse the repository at this point in the history
CMake: Generate and install squirrel.pc
  • Loading branch information
albertodemichelis authored Aug 8, 2023
2 parents 1c1fd9a + 8bf504f commit ac6a095
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
35 changes: 33 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.4)
project(squirrel VERSION 3.2 LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.12)
project(squirrel
VERSION 3.2
DESCRIPTION "The Squirrel programming language"
HOMEPAGE_URL "http://squirrel-lang.org/"
LANGUAGES C CXX
)

option(DISABLE_STATIC "Avoid building/installing static libraries.")
option(LONG_OUTPUT_NAMES "Use longer names for binaries and libraries: squirrel3 (not sq).")
Expand Down Expand Up @@ -33,6 +38,15 @@ elseif(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()

# Need to be defined here to be visible to squirrel.pc.in
if(LONG_OUTPUT_NAMES)
set(LIBSQUIRREL_NAME squirrel3)
set(SQSTDLIB_NAME sqstdlib3)
else()
set(LIBSQUIRREL_NAME squirrel)
set(SQSTDLIB_NAME sqstdlib)
endif()

add_subdirectory(squirrel)
add_subdirectory(sqstdlib)
if(NOT SQ_DISABLE_INTERPRETER)
Expand Down Expand Up @@ -95,6 +109,12 @@ configure_package_config_file(
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/squirrel"
)

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/squirrel.pc.in"
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
@ONLY
)

if(NOT SQ_DISABLE_INSTALLER AND NOT SQ_DISABLE_CMAKE_INSTALLER)
export(EXPORT squirrel
NAMESPACE squirrel::
Expand All @@ -108,6 +128,17 @@ if(NOT SQ_DISABLE_INSTALLER AND NOT SQ_DISABLE_CMAKE_INSTALLER)
COMPONENT Development
)

# pc(5) only allows static variant to have extra flags, not an entirely new
# set of flags. While it's uncommon, a way to do it would be to generate a
# ${PROJECT_NAME}_static.pc file.
if(NOT DISABLE_DYNAMIC)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT Development
)
endif()

install(EXPORT squirrel
NAMESPACE squirrel::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/squirrel"
Expand Down
5 changes: 1 addition & 4 deletions sqstdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if(NOT DISABLE_DYNAMIC)
add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
add_library(squirrel::sqstdlib ALIAS sqstdlib)
set_property(TARGET sqstdlib PROPERTY EXPORT_NAME sqstdlib)
set_property(TARGET sqstdlib PROPERTY OUTPUT_NAME ${SQSTDLIB_NAME})
target_link_libraries(sqstdlib squirrel)
if(NOT SQ_DISABLE_INSTALLER)
install(TARGETS sqstdlib EXPORT squirrel
Expand Down Expand Up @@ -42,10 +43,6 @@ if(NOT DISABLE_STATIC)
endif()

if(LONG_OUTPUT_NAMES)
if(NOT DISABLE_DYNAMIC)
set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
endif()

if(NOT DISABLE_STATIC)
set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static)
endif()
Expand Down
12 changes: 12 additions & 0 deletions squirrel.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: @PROJECT_NAME@
Version: @PROJECT_VERSION@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Requires:
Provides: squirrel3 = @PROJECT_VERSION@
Libs: -L${libdir} -l@LIBSQUIRREL_NAME@ -l@SQSTDLIB_NAME@
Cflags: -I${includedir}
5 changes: 1 addition & 4 deletions squirrel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if(NOT DISABLE_DYNAMIC)
add_library(squirrel SHARED ${SQUIRREL_SRC})
add_library(squirrel::squirrel ALIAS squirrel)
set_property(TARGET squirrel PROPERTY EXPORT_NAME squirrel)
set_property(TARGET squirrel PROPERTY OUTPUT_NAME ${LIBSQUIRREL_NAME})
if(NOT SQ_DISABLE_INSTALLER)
install(TARGETS squirrel EXPORT squirrel
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Libraries
Expand Down Expand Up @@ -45,10 +46,6 @@ if(NOT DISABLE_STATIC)
endif()

if(LONG_OUTPUT_NAMES)
if(NOT DISABLE_DYNAMIC)
set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
endif()

if(NOT DISABLE_STATIC)
set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static)
endif()
Expand Down

0 comments on commit ac6a095

Please sign in to comment.