Skip to content

Commit

Permalink
Better CMake install target
Browse files Browse the repository at this point in the history
  • Loading branch information
bamless committed Jul 16, 2023
1 parent 228d81f commit e63207e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 37 deletions.
39 changes: 35 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.9)

project(jstar)
set(CMAKE_PROJECT_DESCRIPTION "A lightweight embeddable scripting language")
set(CMAKE_PROJECT_HOMEPAGE_URL "https://bamless.github.io/jstar/")

set(JSTAR_VERSION_MAJOR 1)
set(JSTAR_VERSION_MINOR 9)
Expand Down Expand Up @@ -87,25 +90,53 @@ add_subdirectory(src)
add_subdirectory(apps)
add_subdirectory(extern)

# -----------------------------------------------------------------------------
# Installation
# -----------------------------------------------------------------------------

if(JSTAR_INSTALL)
# Install J* library targets
install(TARGETS jstar jstar_static
EXPORT jstar-export
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# Install header files
install(DIRECTORY
${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN "*.h.in" EXCLUDE
)

# Install export files
install(EXPORT jstar-export
FILE JStarTargets.cmake
NAMESPACE jstar::
DESTINATION lib/cmake/jstar
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jstar
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/JStarConfigVersion.cmake
VERSION ${JSTAR_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/JStarConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/JStarConfigVersion.cmake
DESTINATION lib/cmake/jstar
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jstar
)

# Configure and install pkg-config file
configure_file(
${PROJECT_SOURCE_DIR}/cmake/jstar.pc.in
${CMAKE_BINARY_DIR}/jstar.pc
@ONLY
)
install(
FILES ${CMAKE_BINARY_DIR}/jstar.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

# Install license files
Expand Down
2 changes: 1 addition & 1 deletion apps/jstar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ if(JSTAR_INSTALL)

install(TARGETS cli
EXPORT jstar-export
RUNTIME DESTINATION bin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
4 changes: 2 additions & 2 deletions apps/jstarc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ if(JSTAR_INSTALL)

install(TARGETS jstarc
EXPORT jstar-export
RUNTIME DESTINATION bin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
endif()
19 changes: 19 additions & 0 deletions cmake/jstar.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# this template is filled-in by CMake `configure_file(... @ONLY)`
# the `@....@` are filled in by CMake configure_file(),
# from variables set in your CMakeLists.txt or by CMake itself
#
# Good tutoral for understanding .pc files:
# https://people.freedesktop.org/~dbn/pkg-config-guide.html

prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
libdir="${prefix}/lib"
includedir="${prefix}/include"

Name: @PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
URL: @CMAKE_PROJECT_HOMEPAGE_URL@
Version: @JSTAR_VERSION@
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -ljstar
Libs.private: -l@EXTRA_LIBS@
1 change: 0 additions & 1 deletion include/jstar/jstar.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ JSTAR_API void jsrPushNumber(JStarVM* vm, double number);
JSTAR_API void jsrPushBoolean(JStarVM* vm, bool boolean);
JSTAR_API void jsrPushStringSz(JStarVM* vm, const char* string, size_t size);
JSTAR_API void jsrPushString(JStarVM* vm, const char* string);
JSTAR_API void jsrPushBoolean(JStarVM* vm, bool b);
JSTAR_API void jsrPushHandle(JStarVM* vm, void* handle);
JSTAR_API void jsrPushNull(JStarVM* vm);
JSTAR_API void jsrPushList(JStarVM* vm);
Expand Down
38 changes: 9 additions & 29 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ set(JSTAR_SOURCES
)

# J* standard library files
set(JSTAR_STDLIB
set(JSTAR_STDLIB
lib/core/core.jsc
lib/core/std.jsc
lib/core/excs.jsc
Expand Down Expand Up @@ -121,7 +121,7 @@ endif()
add_library(jstar_static STATIC ${JSTAR_SOURCES} ${JSTAR_STDLIB_HEADERS} ${JSTAR_STDLIB})
target_compile_definitions(jstar_static PUBLIC JSTAR_STATIC)
target_link_libraries(jstar_static PUBLIC ${EXTRA_LIBS})
target_include_directories(jstar_static
target_include_directories(jstar_static
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand All @@ -131,15 +131,17 @@ target_include_directories(jstar_static
${PROJECT_SOURCE_DIR}/profile
${PROJECT_BINARY_DIR}
)
set_target_properties(jstar_static PROPERTIES
OUTPUT_NAME "jstars"
VERSION ${JSTAR_VERSION}
)
if(NOT WIN32)
set_target_properties(jstar_static PROPERTIES
OUTPUT_NAME "jstar"
VERSION ${JSTAR_VERSION}
)
endif()

#shared library
add_library(jstar SHARED ${JSTAR_SOURCES} ${JSTAR_STDLIB_HEADERS} ${JSTAR_STDLIB})
target_link_libraries(jstar PUBLIC ${EXTRA_LIBS})
target_include_directories(jstar
target_include_directories(jstar
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand All @@ -165,25 +167,3 @@ if(LTO)
set_target_properties(jstar PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
set_target_properties(jstar_static PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

# -----------------------------------------------------------------------------
# Installation
# -----------------------------------------------------------------------------

# Install target
if(JSTAR_INSTALL)
# Install J* library
install(TARGETS jstar jstar_static
EXPORT jstar-export
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

# Install header files
install(DIRECTORY
${PROJECT_SOURCE_DIR}/include/
DESTINATION include
PATTERN "*.h.in" EXCLUDE
)
endif()

0 comments on commit e63207e

Please sign in to comment.