From e63207e2603de9f40a075a165524a7d884019920 Mon Sep 17 00:00:00 2001 From: Fabrizio Pietrucci Date: Sun, 16 Jul 2023 18:31:28 +0200 Subject: [PATCH] Better CMake install target --- CMakeLists.txt | 39 ++++++++++++++++++++++++++++++++++---- apps/jstar/CMakeLists.txt | 2 +- apps/jstarc/CMakeLists.txt | 4 ++-- cmake/jstar.pc.in | 19 +++++++++++++++++++ include/jstar/jstar.h | 1 - src/CMakeLists.txt | 38 +++++++++---------------------------- 6 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 cmake/jstar.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b21261dd..6b8aa3a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 diff --git a/apps/jstar/CMakeLists.txt b/apps/jstar/CMakeLists.txt index 5f9b23c9..6fc992ec 100644 --- a/apps/jstar/CMakeLists.txt +++ b/apps/jstar/CMakeLists.txt @@ -45,6 +45,6 @@ if(JSTAR_INSTALL) install(TARGETS cli EXPORT jstar-export - RUNTIME DESTINATION bin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) endif() diff --git a/apps/jstarc/CMakeLists.txt b/apps/jstarc/CMakeLists.txt index b0c5a73a..a5416b78 100644 --- a/apps/jstarc/CMakeLists.txt +++ b/apps/jstarc/CMakeLists.txt @@ -26,6 +26,6 @@ if(JSTAR_INSTALL) install(TARGETS jstarc EXPORT jstar-export - RUNTIME DESTINATION bin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) -endif() \ No newline at end of file +endif() diff --git a/cmake/jstar.pc.in b/cmake/jstar.pc.in new file mode 100644 index 00000000..e98a7b84 --- /dev/null +++ b/cmake/jstar.pc.in @@ -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@ diff --git a/include/jstar/jstar.h b/include/jstar/jstar.h index 99f4aedc..92fe6e97 100644 --- a/include/jstar/jstar.h +++ b/include/jstar/jstar.h @@ -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); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e549764..6dcd617b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 @@ -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 $ $ @@ -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 $ $ @@ -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()