From 434a36f0b9c4f3aa38a1ab680d04e527c5ca6986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 08:39:15 +0100 Subject: [PATCH 01/33] remove error on apple/unix and set platform string --- CMakeLists.txt | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c02b5b82..5c0bde2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,14 +15,7 @@ project(chibi-scheme LANGUAGES C VERSION ${version} include(CheckIncludeFile) -if(APPLE) - message(FATAL_ERROR - "DYLD platforms are not supported with this CMakeLists.txt. Use Makefile instead.") -endif() -if(UNIX) - message(FATAL_ERROR - "UNIX platforms are not supported with this CMakeLists.txt. Use Makefile instead.") endif() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -257,8 +250,20 @@ endif() if(WIN32) set(platform "windows") +elseif(CYGWIN) + set(platform "cygwin") +elseif(APPLE) + set(platform "macosx") +elseif(CMAKE_SYSTEM MATCHES "[Bb][Ss][Dd]") + set(platform "bsd") +elseif(CMAKE_SYSTEM MATCHES "[Aa]ndroid") + set(platform "android") +elseif(CMAKE_SYSTEM MATCHES "[Ss]un[Oo][Ss]") + set(platform "solaris") +elseif (CMAKE_SYSTEM MATCHES "[Ll]inux") + set(platform "linux") else() - set(platform "unknown") + set(platform "unix") endif() From e9391c93fbdcde41cbde9a0f14a4ac8374dd11cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 08:57:04 +0100 Subject: [PATCH 02/33] mimic Makefile's ntp and stdint conditional compilation --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c0bde2c..cba9b1fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ project(chibi-scheme LANGUAGES C VERSION ${version} DESCRIPTION "Chibi-Scheme: minimal r7rs implementation, release: ${release}") include(CheckIncludeFile) +include(CheckSymbolExists) endif() @@ -25,7 +26,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # check_include_file(poll.h HAVE_POLL_H) -check_include_file(stdint.h HAVE_STDINT_H) +check_symbol_exists(ntp_gettime sys/timex.h HAVE_NTP_GETTIME) +check_symbol_exists(int_least8_t inttypes.h HAVE_STDINT_H) if (WIN32 AND NOT CYGWIN) set(DEFAULT_SHARED_LIBS OFF) From d7c28021c8d528078702dea7c083394db03c6ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 09:00:49 +0100 Subject: [PATCH 03/33] set default build type, add sanitizer build support --- CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cba9b1fe..7a8d481c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,16 @@ project(chibi-scheme LANGUAGES C VERSION ${version} include(CheckIncludeFile) include(CheckSymbolExists) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +SET(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING + "Build type: None, Debug, Release, RelWithDebInfo, MinSizeRel, or Sanitizer." FORCE) + +if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt AND NOT CMAKE_BUILD_TYPE) + # CMake doesn't have a default build type, so set one manually + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) endif() -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # # Features @@ -86,6 +92,12 @@ if(NOT HAVE_POLL_H) target_compile_definitions(libchibi-common INTERFACE SEXP_USE_GREEN_THREADS=0) endif() +target_compile_options(libchibi-common + INTERFACE + $<$<CONFIG:SANITIZER>:-g + -fsanitize=address,undefined,integer-divide-by-zero,float-divide-by-zero,float-cast-overflow,return + -fno-omit-frame-pointer>) + # # Sources # From 36f7d86cad190548f3cbe423aea9a11c42ec8e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 09:02:01 +0100 Subject: [PATCH 04/33] fix CMake 3.12 list(REMOVE ...) invocation --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a8d481c..383b6b26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,7 +159,11 @@ file(GLOB_RECURSE stubs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.stub) file(GLOB_RECURSE slds RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.sld) -list(REMOVE_ITEM slds ${chibi-scheme-exclude-modules}) +if (chibi-scheme-exclude-modules) + # CMake doesn't complain anymore about an empty 2nd argument, but 3.12 does. When we require a + # more recent version, the if-guard should go. + list(REMOVE_ITEM slds ${chibi-scheme-exclude-modules}) +endif() set(chibi-ffi ${CMAKE_CURRENT_SOURCE_DIR}/tools/chibi-ffi) set(chibi-genstatic ${CMAKE_CURRENT_SOURCE_DIR}/tools/chibi-genstatic) From b8a350022265e2da239e3f46f21fe5370e35b86d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 09:02:22 +0100 Subject: [PATCH 05/33] build with -Wall when using clang or gcc --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 383b6b26..d8206387 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,11 @@ if (NOT BUILD_SHARED_LIBS) target_compile_definitions(libchibi-common INTERFACE SEXP_STATIC_LIBRARY=1) endif() +target_compile_options(libchibi-common + INTERFACE + $<$<C_COMPILER_ID:GNU>:-Wall> + $<$<OR:$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>>:-Wall>) + target_include_directories(libchibi-common INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> From 584bfa225c7d25c46c7134a174ae774b33801383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 09:03:20 +0100 Subject: [PATCH 06/33] mimic Makefile's option for cygwin build --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8206387..286e0f64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,10 @@ if(NOT HAVE_POLL_H) target_compile_definitions(libchibi-common INTERFACE SEXP_USE_GREEN_THREADS=0) endif() +if(CYGWIN) + target_compile_definitions(libchibi-common INTERFACE SEXP_USE_STRING_STREAMS=0) +endif() + target_compile_options(libchibi-common INTERFACE $<$<CONFIG:SANITIZER>:-g From 3b33a9561a9d8cc7cbdb7f1bcb208c21e9cbb496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 09:03:55 +0100 Subject: [PATCH 07/33] add SEXP_USE_BOEHM configuration option --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 286e0f64..c7bc8e8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ else() endif() option(BUILD_SHARED_LIBS "Build chibi-scheme as a shared library" ${DEFAULT_SHARED_LIBS}) +option(SEXP_USE_BOEHM "Use Boehm garbage collection library" OFF) set(chibi-scheme-exclude-modules) if(WIN32) @@ -101,6 +102,18 @@ if(CYGWIN) target_compile_definitions(libchibi-common INTERFACE SEXP_USE_STRING_STREAMS=0) endif() +if(SEXP_USE_BOEHM) + find_library(BOEHMGC gc REQUIRED) + find_path(BOEHMGC_INCLUDE NAMES gc/gc.h) + target_compile_definitions(libchibi-common INTERFACE SEXP_USE_BOEHM=1) + target_include_directories(libchibi-common INTERFACE ${BOEHMGC_INCLUDE}) + target_link_libraries(libchibi-common INTERFACE ${BOEHMGC} + $<$<CONFIG:SANITIZER>:-fsanitize=address,undefined>) +else() + target_link_libraries(libchibi-common INTERFACE + $<$<CONFIG:SANITIZER>:-fsanitize=address,undefined>) +endif() + target_compile_options(libchibi-common INTERFACE $<$<CONFIG:SANITIZER>:-g From 2efcc53098d613f719c8fb16e3b67254597676ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 09:05:37 +0100 Subject: [PATCH 08/33] compile shared libraries for non-static builds --- CMakeLists.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7bc8e8a..a9f7c49e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,6 +212,55 @@ add_custom_target(chibi-scheme-stubs DEPENDS ${stubouts}) add_dependencies(libchibi-scheme chibi-scheme-stubs) +function(add_compiled_library cfile) + get_filename_component(basename ${cfile} NAME_WE) + get_filename_component(libdir ${cfile} DIRECTORY) + string(REPLACE "/" "-" libname ${libdir}/${basename}) + set(outputdir ${CMAKE_CURRENT_BINARY_DIR}/${libdir}) + + if (NOT BUILD_SHARED_LIBS) + return() + endif() + add_library(${libname} ${cfile}) + target_link_libraries(${libname} + PRIVATE + libchibi-scheme) + + set_target_properties(${libname} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${outputdir} + LIBRARY_OUTPUT_NAME ${basename} + PREFIX "") +endfunction() + +add_compiled_library(lib/chibi/filesystem.c) +add_compiled_library(lib/chibi/weak.c) +add_compiled_library(lib/chibi/heap-stats.c) +add_compiled_library(lib/chibi/disasm.c) +add_compiled_library(lib/chibi/ast.c) +add_compiled_library(lib/chibi/json.c) +add_compiled_library(lib/chibi/emscripten.c) +add_compiled_library(lib/chibi/process.c) +add_compiled_library(lib/chibi/time.c) +add_compiled_library(lib/chibi/system.c) +add_compiled_library(lib/chibi/stty.c) +add_compiled_library(lib/chibi/pty.c) +add_compiled_library(lib/chibi/net.c) +add_compiled_library(lib/srfi/18/threads.c) +add_compiled_library(lib/chibi/io/io.c) +add_compiled_library(lib/chibi/optimize/rest.c) +add_compiled_library(lib/chibi/optimize/profile.c) +add_compiled_library(lib/chibi/crypto/crypto.c) +add_compiled_library(lib/srfi/27/rand.c) +add_compiled_library(lib/srfi/151/bit.c) +add_compiled_library(lib/srfi/39/param.c) +add_compiled_library(lib/srfi/69/hash.c) +add_compiled_library(lib/srfi/95/qsort.c) +add_compiled_library(lib/srfi/98/env.c) +add_compiled_library(lib/srfi/144/math.c) +add_compiled_library(lib/srfi/160/uvprims.c) +add_compiled_library(lib/scheme/bytevector.c) +add_compiled_library(lib/scheme/time.c) + # # Generate clib.c for SEXP_USE_STATIC_LIBS # From 0bade8de2f8a83b00f4fdc936a944f9928ee5586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 09:05:51 +0100 Subject: [PATCH 09/33] refactor library generation from stubs --- CMakeLists.txt | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9f7c49e..e1b2b76d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,26 +190,40 @@ endif() set(chibi-ffi ${CMAKE_CURRENT_SOURCE_DIR}/tools/chibi-ffi) set(chibi-genstatic ${CMAKE_CURRENT_SOURCE_DIR}/tools/chibi-genstatic) -set(stuboutdir ${CMAKE_CURRENT_BINARY_DIR}/stubs/lib) -foreach(e ${stubs}) - get_filename_component(stubdir ${e} PATH) - get_filename_component(basename ${e} NAME_WE) - set(stubfile ${CMAKE_CURRENT_SOURCE_DIR}/lib/${e}) - set(stubdir ${stuboutdir}/${stubdir}) +function(add_stubs_library stub stubc) + get_filename_component(stubdir ${stub} PATH) + get_filename_component(basename ${stub} NAME_WE) + set(stubfile ${CMAKE_CURRENT_SOURCE_DIR}/lib/${stub}) + set(stubdir ${CMAKE_CURRENT_BINARY_DIR}/lib/${stubdir}) set(stubout ${stubdir}/${basename}.c) + set(${stubc} ${stubout} PARENT_SCOPE) + file(MAKE_DIRECTORY ${stubdir}) add_custom_command(OUTPUT ${stubout} - COMMAND chibi-scheme-bootstrap - ${chibi-ffi} ${stubfile} ${stubout} + COMMAND chibi-scheme-bootstrap ${chibi-ffi} ${stubfile} ${stubout} DEPENDS ${stubfile} ${chibi-ffi} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - list(APPEND stubouts ${stubout}) + + if (BUILD_SHARED_LIBS) + add_library(${basename} + ${stubout}) + + target_link_libraries(${basename} + PRIVATE + libchibi-scheme) + + set_target_properties(${basename} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${stubdir} + LIBRARY_OUTPUT_NAME ${basename} + PREFIX "") + endif() +endfunction() + +foreach(stub ${stubs}) + add_stubs_library(${stub} stubc) + list(APPEND stubouts ${stubc}) endforeach() add_custom_target(chibi-scheme-stubs DEPENDS ${stubouts}) - - - - add_dependencies(libchibi-scheme chibi-scheme-stubs) function(add_compiled_library cfile) From 17ffa4b36ce9e9bb30ce5cd4a85f153e50866337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 10:35:49 +0100 Subject: [PATCH 10/33] use sensible default module paths for Linux/Unix --- CMakeLists.txt | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1b2b76d..f03977a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ project(chibi-scheme LANGUAGES C VERSION ${version} include(CheckIncludeFile) include(CheckSymbolExists) +include(GNUInstallDirs) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -339,18 +340,6 @@ bless_chibi_scheme_executable(chibi-scheme) # Generate "chibi/install.h" # -if(CYGWIN OR WIN32) - set(thePrefix "bin") -else() - set(thePrefix "lib") -endif() - -if(WIN32) - set(pathsep "\\;") -else() - set(pathsep ":") -endif() - if(WIN32) set(platform "windows") elseif(CYGWIN) @@ -370,10 +359,11 @@ else() endif() -set(default_module_path - "" - #"${CMAKE_INSTALL_PREFIX}/${thePrefix}${pathsep}${CMAKE_INSTALL_PREFIX}/bin" - ) +string(JOIN ":" default_module_path + ${CMAKE_INSTALL_FULL_DATAROOTDIR}/chibi + ${CMAKE_INSTALL_FULL_LIBDIR}/chibi + ${CMAKE_INSTALL_FULL_DATAROOTDIR}/snow + ${CMAKE_INSTALL_FULL_LIBDIR}/snow) configure_file(include/chibi/install.h.in include/chibi/install.h) From 82aa16a3f124b7e26959619399806adf12336e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Mon, 31 May 2021 22:40:52 +0100 Subject: [PATCH 11/33] compile shared libraries for non-static configurations --- CMakeLists.txt | 108 ++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 59 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f03977a3..5d7830ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,13 +175,9 @@ set_target_properties(libchibi-scheme # # Generate modules # -# FIXME: Currently, it depends on GLOB thus we have to re-run CMake -# when we've gotten additional/removed library -file(GLOB_RECURSE stubs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib - ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.stub) file(GLOB_RECURSE slds RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.sld) + CONFIGURE_DEPENDS lib/*.sld) if (chibi-scheme-exclude-modules) # CMake doesn't complain anymore about an empty 2nd argument, but 3.12 does. When we require a # more recent version, the if-guard should go. @@ -191,13 +187,37 @@ endif() set(chibi-ffi ${CMAKE_CURRENT_SOURCE_DIR}/tools/chibi-ffi) set(chibi-genstatic ${CMAKE_CURRENT_SOURCE_DIR}/tools/chibi-genstatic) -function(add_stubs_library stub stubc) +function(add_compiled_library cfile) + if (NOT BUILD_SHARED_LIBS) + return() + endif() + + get_filename_component(basename ${cfile} NAME_WE) + get_filename_component(libdir ${cfile} DIRECTORY) + + if(NOT IS_ABSOLUTE ${libdir}) + set(libdir ${CMAKE_CURRENT_BINARY_DIR}/${libdir}) + endif() + + file(RELATIVE_PATH libname ${CMAKE_CURRENT_BINARY_DIR} ${libdir}/${basename}) + string(REPLACE "/" "-" libname ${libname}) + + add_library(${libname} ${cfile}) + target_link_libraries(${libname} PRIVATE libchibi-scheme) + + set_target_properties(${libname} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${libdir} + LIBRARY_OUTPUT_NAME ${basename} + PREFIX "") +endfunction() + +function(add_stubs_library stub) get_filename_component(stubdir ${stub} PATH) get_filename_component(basename ${stub} NAME_WE) - set(stubfile ${CMAKE_CURRENT_SOURCE_DIR}/lib/${stub}) - set(stubdir ${CMAKE_CURRENT_BINARY_DIR}/lib/${stubdir}) + set(stubfile ${CMAKE_CURRENT_SOURCE_DIR}/${stub}) + set(stubdir ${CMAKE_CURRENT_BINARY_DIR}/${stubdir}) set(stubout ${stubdir}/${basename}.c) - set(${stubc} ${stubout} PARENT_SCOPE) + set(stubouts ${stubouts} ${stubout} PARENT_SCOPE) file(MAKE_DIRECTORY ${stubdir}) add_custom_command(OUTPUT ${stubout} @@ -205,75 +225,45 @@ function(add_stubs_library stub stubc) DEPENDS ${stubfile} ${chibi-ffi} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - if (BUILD_SHARED_LIBS) - add_library(${basename} - ${stubout}) - - target_link_libraries(${basename} - PRIVATE - libchibi-scheme) - - set_target_properties(${basename} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${stubdir} - LIBRARY_OUTPUT_NAME ${basename} - PREFIX "") - endif() + add_compiled_library(${stubout}) endfunction() -foreach(stub ${stubs}) - add_stubs_library(${stub} stubc) - list(APPEND stubouts ${stubc}) -endforeach() +add_stubs_library(lib/chibi/crypto/crypto.stub) +add_stubs_library(lib/chibi/emscripten.stub) +add_stubs_library(lib/chibi/filesystem.stub) +add_stubs_library(lib/chibi/io/io.stub) +add_stubs_library(lib/scheme/bytevector.stub) +add_stubs_library(lib/srfi/144/math.stub) +add_stubs_library(lib/srfi/160/uvprims.stub) + +if(NOT WIN32) + add_stubs_library(lib/chibi/net.stub) + add_stubs_library(lib/chibi/process.stub) + add_stubs_library(lib/chibi/pty.stub) + add_stubs_library(lib/chibi/stty.stub) + add_stubs_library(lib/chibi/system.stub) + add_stubs_library(lib/chibi/time.stub) +else() + add_stubs_library(lib/chibi/win32/process-win32.stub) +endif() + add_custom_target(chibi-scheme-stubs DEPENDS ${stubouts}) add_dependencies(libchibi-scheme chibi-scheme-stubs) -function(add_compiled_library cfile) - get_filename_component(basename ${cfile} NAME_WE) - get_filename_component(libdir ${cfile} DIRECTORY) - string(REPLACE "/" "-" libname ${libdir}/${basename}) - set(outputdir ${CMAKE_CURRENT_BINARY_DIR}/${libdir}) - - if (NOT BUILD_SHARED_LIBS) - return() - endif() - add_library(${libname} ${cfile}) - target_link_libraries(${libname} - PRIVATE - libchibi-scheme) - - set_target_properties(${libname} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${outputdir} - LIBRARY_OUTPUT_NAME ${basename} - PREFIX "") -endfunction() - -add_compiled_library(lib/chibi/filesystem.c) add_compiled_library(lib/chibi/weak.c) add_compiled_library(lib/chibi/heap-stats.c) add_compiled_library(lib/chibi/disasm.c) add_compiled_library(lib/chibi/ast.c) add_compiled_library(lib/chibi/json.c) -add_compiled_library(lib/chibi/emscripten.c) -add_compiled_library(lib/chibi/process.c) -add_compiled_library(lib/chibi/time.c) -add_compiled_library(lib/chibi/system.c) -add_compiled_library(lib/chibi/stty.c) -add_compiled_library(lib/chibi/pty.c) -add_compiled_library(lib/chibi/net.c) add_compiled_library(lib/srfi/18/threads.c) -add_compiled_library(lib/chibi/io/io.c) add_compiled_library(lib/chibi/optimize/rest.c) add_compiled_library(lib/chibi/optimize/profile.c) -add_compiled_library(lib/chibi/crypto/crypto.c) add_compiled_library(lib/srfi/27/rand.c) add_compiled_library(lib/srfi/151/bit.c) add_compiled_library(lib/srfi/39/param.c) add_compiled_library(lib/srfi/69/hash.c) add_compiled_library(lib/srfi/95/qsort.c) add_compiled_library(lib/srfi/98/env.c) -add_compiled_library(lib/srfi/144/math.c) -add_compiled_library(lib/srfi/160/uvprims.c) -add_compiled_library(lib/scheme/bytevector.c) add_compiled_library(lib/scheme/time.c) # From d06d56154ed75613b1c86115353b005df4bddf55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Tue, 1 Jun 2021 21:42:58 +0100 Subject: [PATCH 12/33] replace custom function with target_link_libraries --- CMakeLists.txt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d7830ef..d8df59b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -310,13 +310,6 @@ elseif(WIN32) target_compile_definitions(libchibi-scheme PUBLIC BUILDING_DLL=1) endif() -function(bless_chibi_scheme_executable tgt) - target_link_libraries(${tgt} libchibi-scheme) - if(WIN32 AND NOT ${BUILD_SHARED_LIBS}) - target_link_libraries(${tgt} ws2_32) - endif() -endfunction() - # # Interpreter # @@ -324,7 +317,8 @@ endfunction() add_executable(chibi-scheme main.c) -bless_chibi_scheme_executable(chibi-scheme) +target_link_libraries(chibi-scheme + PRIVATE libchibi-scheme) # # Generate "chibi/install.h" @@ -427,7 +421,8 @@ endforeach() add_executable(test-foreign-apply-loop tests/foreign/apply-loop.c) -bless_chibi_scheme_executable(test-foreign-apply-loop) +target_link_libraries(test-foreign-apply-loop + PRIVATE libchibi-scheme) add_test(NAME "foreign-apply-loop" COMMAND test-foreign-apply-loop @@ -436,7 +431,8 @@ add_test(NAME "foreign-apply-loop" add_executable(test-foreign-typeid tests/foreign/typeid.c) -bless_chibi_scheme_executable(test-foreign-typeid) +target_link_libraries(test-foreign-typeid + PRIVATE libchibi-scheme) add_test(NAME "foreign-typeid" COMMAND test-foreign-typeid From 1b960f949f343fc5fb6ee8cfeede3209e5dae000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Tue, 1 Jun 2021 21:43:41 +0100 Subject: [PATCH 13/33] add module search path to test runs --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8df59b8..5c1c00ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -370,7 +370,7 @@ set(chibi-scheme-tests foreach(e ${chibi-scheme-tests}) add_test(NAME "${e}" - COMMAND chibi-scheme tests/${e}.scm + COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib tests/${e}.scm WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() @@ -409,7 +409,8 @@ foreach(e ${testlibs}) string(REGEX REPLACE "/" "_" testname ${e}) string(REGEX REPLACE "/" " " form ${e}) add_test(NAME "lib_${testname}" - COMMAND chibi-scheme -e "(import (${form}))" + COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib + -e "(import (${form}))" -e "(run-tests)" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() From 9652d08ae388eaa020816776a183c4d4d71cda90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 2 Jun 2021 10:37:17 +0100 Subject: [PATCH 14/33] reorganize linking of common configuration library --- CMakeLists.txt | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c1c00ea..1e7e0d24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,11 @@ endif() option(BUILD_SHARED_LIBS "Build chibi-scheme as a shared library" ${DEFAULT_SHARED_LIBS}) option(SEXP_USE_BOEHM "Use Boehm garbage collection library" OFF) +if(SEXP_USE_BOEHM) + find_library(BOEHMGC gc REQUIRED) + find_path(BOEHMGC_INCLUDE NAMES gc/gc.h) +endif() + set(chibi-scheme-exclude-modules) if(WIN32) set(chibi-scheme-exclude-modules @@ -67,6 +72,8 @@ add_library(libchibi-common if (NOT BUILD_SHARED_LIBS) target_compile_definitions(libchibi-common INTERFACE SEXP_STATIC_LIBRARY=1) +elseif(WIN32) + target_compile_definitions(libchibi-common INTERFACE BUILDING_DLL=1) endif() target_compile_options(libchibi-common @@ -76,6 +83,7 @@ target_compile_options(libchibi-common target_include_directories(libchibi-common INTERFACE + ${BOEHMGC_INCLUDE} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) @@ -104,17 +112,14 @@ if(CYGWIN) endif() if(SEXP_USE_BOEHM) - find_library(BOEHMGC gc REQUIRED) - find_path(BOEHMGC_INCLUDE NAMES gc/gc.h) target_compile_definitions(libchibi-common INTERFACE SEXP_USE_BOEHM=1) - target_include_directories(libchibi-common INTERFACE ${BOEHMGC_INCLUDE}) - target_link_libraries(libchibi-common INTERFACE ${BOEHMGC} - $<$<CONFIG:SANITIZER>:-fsanitize=address,undefined>) -else() - target_link_libraries(libchibi-common INTERFACE - $<$<CONFIG:SANITIZER>:-fsanitize=address,undefined>) endif() +target_link_libraries(libchibi-common INTERFACE + ${BOEHMGC} + $<$<CONFIG:SANITIZER>:-fsanitize=address,undefined> + $<$<PLATFORM_ID:Windows>:ws2_32>) + target_compile_options(libchibi-common INTERFACE $<$<CONFIG:SANITIZER>:-g @@ -147,13 +152,7 @@ add_executable(chibi-scheme-bootstrap ${chibi-scheme-srcs} main.c) -if(WIN32) - target_link_libraries(chibi-scheme-bootstrap - PRIVATE ws2_32 libchibi-common) -else() - target_link_libraries(chibi-scheme-bootstrap - PRIVATE libchibi-common) -endif() +target_link_libraries(chibi-scheme-bootstrap PRIVATE libchibi-common) # @@ -305,9 +304,6 @@ if (NOT BUILD_SHARED_LIBS) INTERFACE $<BUILD_INTERFACE:${stuboutdir}/..> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) -elseif(WIN32) - target_link_libraries(libchibi-scheme ws2_32) - target_compile_definitions(libchibi-scheme PUBLIC BUILDING_DLL=1) endif() # From 46fbc423d30d427b1bfabcaa21b5d2edc400cd5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 2 Jun 2021 10:53:58 +0100 Subject: [PATCH 15/33] shorten preprocessor configuration --- CMakeLists.txt | 53 +++++++++++++------------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e7e0d24..63c53a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,16 +70,24 @@ endif() add_library(libchibi-common INTERFACE) -if (NOT BUILD_SHARED_LIBS) - target_compile_definitions(libchibi-common INTERFACE SEXP_STATIC_LIBRARY=1) -elseif(WIN32) - target_compile_definitions(libchibi-common INTERFACE BUILDING_DLL=1) -endif() +target_compile_definitions(libchibi-common + INTERFACE + SEXP_STATIC_LIBRARY=$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>> + BUILDING_DLL=$<AND:$<PLATFORM_ID:Windows>,$<BOOL:${BUILD_SHARED_LIBS}>> + SEXP_USE_DL=$<BOOL:${BUILD_SHARED_LIBS}> + SEXP_USE_INTTYPES=$<BOOL:${HAVE_STDINT_H}> + SEXP_USE_NTPGETTIME=$<BOOL:HAVE_NTP_GETTIME> + SEXP_USE_GREEN_THREADS=$<BOOL:HAVE_POLL_H> + SEXP_USE_STRING_STREAMS=$<NOT:$<BOOL:${CYGWIN}>> + SEXP_USE_BOEHM=$<BOOL:${SEXP_USE_BOEHM}>) target_compile_options(libchibi-common INTERFACE $<$<C_COMPILER_ID:GNU>:-Wall> - $<$<OR:$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>>:-Wall>) + $<$<OR:$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>>:-Wall> + $<$<CONFIG:SANITIZER>:-g + -fsanitize=address,undefined,integer-divide-by-zero,float-divide-by-zero,float-cast-overflow,return + -fno-omit-frame-pointer>) target_include_directories(libchibi-common INTERFACE @@ -88,44 +96,11 @@ target_include_directories(libchibi-common $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) -if (NOT BUILD_SHARED_LIBS) - target_compile_definitions(libchibi-common INTERFACE SEXP_USE_DL=0) -else() - target_compile_definitions(libchibi-common INTERFACE SEXP_USE_DL=1) -endif() - -if(HAVE_STDINT_H) - target_compile_definitions(libchibi-common INTERFACE SEXP_USE_INTTYPES) -endif() - -if(HAVE_NTP_GETTIME) - target_compile_definitions(libchibi-common INTERFACE SEXP_USE_NTPGETTIME) -endif() - -if(NOT HAVE_POLL_H) - # Disable green threads: It depends on non-blocking I/O - target_compile_definitions(libchibi-common INTERFACE SEXP_USE_GREEN_THREADS=0) -endif() - -if(CYGWIN) - target_compile_definitions(libchibi-common INTERFACE SEXP_USE_STRING_STREAMS=0) -endif() - -if(SEXP_USE_BOEHM) - target_compile_definitions(libchibi-common INTERFACE SEXP_USE_BOEHM=1) -endif() - target_link_libraries(libchibi-common INTERFACE ${BOEHMGC} $<$<CONFIG:SANITIZER>:-fsanitize=address,undefined> $<$<PLATFORM_ID:Windows>:ws2_32>) -target_compile_options(libchibi-common - INTERFACE - $<$<CONFIG:SANITIZER>:-g - -fsanitize=address,undefined,integer-divide-by-zero,float-divide-by-zero,float-cast-overflow,return - -fno-omit-frame-pointer>) - # # Sources # From 15be95344685735fed9daa2e371c4a86b1f2f953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 2 Jun 2021 11:16:16 +0100 Subject: [PATCH 16/33] fix missing variable dereferencing syntax --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63c53a8b..65da281d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,8 +76,8 @@ target_compile_definitions(libchibi-common BUILDING_DLL=$<AND:$<PLATFORM_ID:Windows>,$<BOOL:${BUILD_SHARED_LIBS}>> SEXP_USE_DL=$<BOOL:${BUILD_SHARED_LIBS}> SEXP_USE_INTTYPES=$<BOOL:${HAVE_STDINT_H}> - SEXP_USE_NTPGETTIME=$<BOOL:HAVE_NTP_GETTIME> - SEXP_USE_GREEN_THREADS=$<BOOL:HAVE_POLL_H> + SEXP_USE_NTPGETTIME=$<BOOL:${HAVE_NTP_GETTIME}> + SEXP_USE_GREEN_THREADS=$<BOOL:${HAVE_POLL_H}> SEXP_USE_STRING_STREAMS=$<NOT:$<BOOL:${CYGWIN}>> SEXP_USE_BOEHM=$<BOOL:${SEXP_USE_BOEHM}>) From 57410deca96e19fcd57ea4c5c5af384b05e59eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 2 Jun 2021 11:29:04 +0100 Subject: [PATCH 17/33] fix string stream config on windows --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65da281d..d9eb2001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,7 @@ target_compile_definitions(libchibi-common SEXP_USE_INTTYPES=$<BOOL:${HAVE_STDINT_H}> SEXP_USE_NTPGETTIME=$<BOOL:${HAVE_NTP_GETTIME}> SEXP_USE_GREEN_THREADS=$<BOOL:${HAVE_POLL_H}> - SEXP_USE_STRING_STREAMS=$<NOT:$<BOOL:${CYGWIN}>> + SEXP_USE_STRING_STREAMS=$<NOT:$<PLATFORM_ID:Windows>> SEXP_USE_BOEHM=$<BOOL:${SEXP_USE_BOEHM}>) target_compile_options(libchibi-common From f58dfdb67d5f55f8118d1ecc55fca0fda7597110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 2 Jun 2021 21:00:47 +0100 Subject: [PATCH 18/33] shorten sanitizer configuration --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9eb2001..8db9083e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ target_compile_options(libchibi-common $<$<C_COMPILER_ID:GNU>:-Wall> $<$<OR:$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>>:-Wall> $<$<CONFIG:SANITIZER>:-g - -fsanitize=address,undefined,integer-divide-by-zero,float-divide-by-zero,float-cast-overflow,return + -fsanitize=address,undefined,integer,float-divide-by-zero,float-cast-overflow,return -fno-omit-frame-pointer>) target_include_directories(libchibi-common From de4fa6439a79cb7d042298260286d9471fc7501f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 2 Jun 2021 22:19:43 +0100 Subject: [PATCH 19/33] use bootstrap exec only for static builds --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8db9083e..cbbf07c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,8 +194,13 @@ function(add_stubs_library stub) set(stubouts ${stubouts} ${stubout} PARENT_SCOPE) file(MAKE_DIRECTORY ${stubdir}) + + add_custom_command(OUTPUT ${stubout} - COMMAND chibi-scheme-bootstrap ${chibi-ffi} ${stubfile} ${stubout} + # This makes sure we only use the separate bootstrap executable for static + # builds. With dynamic linking, the default executable is fine. + COMMAND $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,chibi-scheme,chibi-scheme-bootstrap> + ${chibi-ffi} ${stubfile} ${stubout} DEPENDS ${stubfile} ${chibi-ffi} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) @@ -222,7 +227,10 @@ else() endif() add_custom_target(chibi-scheme-stubs DEPENDS ${stubouts}) -add_dependencies(libchibi-scheme chibi-scheme-stubs) + +if (NOT BUILD_SHARED_LIBS) + add_dependencies(libchibi-scheme chibi-scheme-stubs) +endif() add_compiled_library(lib/chibi/weak.c) add_compiled_library(lib/chibi/heap-stats.c) From 9c22b7d1c221c52317a5455fa6aae88aaa94e7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 2 Jun 2021 22:35:48 +0100 Subject: [PATCH 20/33] comply with older CMake versions (dependency graph) --- CMakeLists.txt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbbf07c4..10bfae4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,17 @@ function(add_compiled_library cfile) PREFIX "") endfunction() +if(BUILD_SHARED_LIBS) + # This makes sure we only use the separate bootstrap executable for static + # builds. With dynamic linking, the default executable is fine. The dispatch + # is not a generator expression within the actual custom command to process + # the stubs, as older CMake versions fail to properly construct the dependency + # on the bootstrap executable from the generator expression. + set(bootstrap chibi-scheme) +else() + set(bootstrap chibi-scheme-bootstrap) +endif() + function(add_stubs_library stub) get_filename_component(stubdir ${stub} PATH) get_filename_component(basename ${stub} NAME_WE) @@ -197,10 +208,7 @@ function(add_stubs_library stub) add_custom_command(OUTPUT ${stubout} - # This makes sure we only use the separate bootstrap executable for static - # builds. With dynamic linking, the default executable is fine. - COMMAND $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,chibi-scheme,chibi-scheme-bootstrap> - ${chibi-ffi} ${stubfile} ${stubout} + COMMAND ${bootstrap} ${chibi-ffi} ${stubfile} ${stubout} DEPENDS ${stubfile} ${chibi-ffi} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) From fcfd518a0d46eb2f9f72315885637e5098050e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Thu, 3 Jun 2021 20:36:37 +0100 Subject: [PATCH 21/33] leave selected zero feature macros undefined --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10bfae4e..f3ae11b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,13 +73,13 @@ add_library(libchibi-common target_compile_definitions(libchibi-common INTERFACE SEXP_STATIC_LIBRARY=$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>> - BUILDING_DLL=$<AND:$<PLATFORM_ID:Windows>,$<BOOL:${BUILD_SHARED_LIBS}>> SEXP_USE_DL=$<BOOL:${BUILD_SHARED_LIBS}> + $<$<PLATFORM_ID:Windows>:BUILDING_DLL=$<BOOL:${BUILD_SHARED_LIBS}>> SEXP_USE_INTTYPES=$<BOOL:${HAVE_STDINT_H}> SEXP_USE_NTPGETTIME=$<BOOL:${HAVE_NTP_GETTIME}> - SEXP_USE_GREEN_THREADS=$<BOOL:${HAVE_POLL_H}> - SEXP_USE_STRING_STREAMS=$<NOT:$<PLATFORM_ID:Windows>> - SEXP_USE_BOEHM=$<BOOL:${SEXP_USE_BOEHM}>) + $<$<NOT:$<BOOL:${HAVE_POLL_H}>>:SEXP_USE_GREEN_THREADS=0> + $<$<PLATFORM_ID:Windows>:SEXP_USE_STRING_STREAMS=0> + $<$<BOOL:${SEXP_USE_BOEHM}>:SEXP_USE_BOEHM=1>) target_compile_options(libchibi-common INTERFACE From 86c439a4bbdb133340dc2a3c1775b4976fa8a748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Thu, 3 Jun 2021 20:47:23 +0100 Subject: [PATCH 22/33] enable more tetst on unix builds --- CMakeLists.txt | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3ae11b4..3266e48c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -346,14 +346,9 @@ enable_testing() set(chibi-scheme-tests r7rs-tests - ## Not connected - #division-tests - #r5rs-tests - #syntax-tests - #unicode-tests - ## Require threads - # lib-tests - ) + division-tests + syntax-tests + unicode-tests) foreach(e ${chibi-scheme-tests}) add_test(NAME "${e}" @@ -361,13 +356,20 @@ foreach(e ${chibi-scheme-tests}) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() +add_test(NAME r5rs-test + COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib -xchibi tests/r5rs-tests.scm + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + file(GLOB_RECURSE srfi_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib - ${CMAKE_CURRENT_SOURCE_DIR}/lib/srfi/*/test.sld) + CONFIGURE_DEPENDS lib/srfi/*/test.sld) file(GLOB_RECURSE chibi_scheme_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib - ${CMAKE_CURRENT_SOURCE_DIR}/lib/chibi/*-test.sld) + CONFIGURE_DEPENDS lib/chibi/*-test.sld) set(testexcludes + chibi/weak-test) + +set(win32testexcludes # Excluded tests chibi/filesystem-test chibi/memoize-test @@ -384,14 +386,18 @@ set(testexcludes chibi/pty-test # Depends (chibi pty) ) -set(testlibs) foreach(e ${srfi_tests} ${chibi_scheme_tests}) get_filename_component(pth ${e} PATH) get_filename_component(nam ${e} NAME_WE) list(APPEND testlibs ${pth}/${nam}) endforeach() + list(REMOVE_ITEM testlibs ${testexcludes}) +if(WIN32) + list(REMOVE_ITEM testlibs ${win32testexcludes}) +endif() + foreach(e ${testlibs}) string(REGEX REPLACE "/" "_" testname ${e}) string(REGEX REPLACE "/" " " form ${e}) From 7de835bad80ae166e5b89bc1062fc6542aee0893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Thu, 3 Jun 2021 21:18:49 +0100 Subject: [PATCH 23/33] improve module path handling and provide basic installation --- CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3266e48c..e962c70a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,8 @@ endif() # # Default settings for all targets. We use an interface library here to not -# pollute/mutate global settings. +# pollute/mutate global settings. Any configuration applied to this library +# is propagated to its client targets. # add_library(libchibi-common @@ -336,6 +337,16 @@ string(JOIN ":" default_module_path ${CMAKE_INSTALL_FULL_DATAROOTDIR}/snow ${CMAKE_INSTALL_FULL_LIBDIR}/snow) +# This file will only be used during an installation (and renamed to install.h) +configure_file(include/chibi/install.h.in include/chibi/to-install.h) + +# This configuration is for development purpose: a chibi executable shall find +# both compiled libraries in its own build directory and scheme source libraries +# in the source directory. +string(JOIN ":" default_module_path + ${CMAKE_CURRENT_BINARY_DIR}/lib + ${CMAKE_CURRENT_SOURCE_DIR}/lib) + configure_file(include/chibi/install.h.in include/chibi/install.h) # @@ -352,12 +363,12 @@ set(chibi-scheme-tests foreach(e ${chibi-scheme-tests}) add_test(NAME "${e}" - COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib tests/${e}.scm + COMMAND chibi-scheme tests/${e}.scm WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() add_test(NAME r5rs-test - COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib -xchibi tests/r5rs-tests.scm + COMMAND chibi-scheme -xchibi tests/r5rs-tests.scm WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) file(GLOB_RECURSE srfi_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib @@ -402,9 +413,7 @@ foreach(e ${testlibs}) string(REGEX REPLACE "/" "_" testname ${e}) string(REGEX REPLACE "/" " " form ${e}) add_test(NAME "lib_${testname}" - COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib - -e "(import (${form}))" - -e "(run-tests)" + COMMAND chibi-scheme -e "(import (${form}))" -e "(run-tests)" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() @@ -431,3 +440,23 @@ target_link_libraries(test-foreign-typeid add_test(NAME "foreign-typeid" COMMAND test-foreign-typeid WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + +# +# Installation +# + +install(DIRECTORY include/chibi + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + USE_SOURCE_PERMISSIONS + PATTERN "sexp-*.[hc]" EXCLUDE + PATTERN "*.h.in" EXCLUDE) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/chibi/to-install.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/chibi + RENAME install.h) + +add_library(chibi::chibi ALIAS libchibi-scheme) + +install(TARGETS libchibi-scheme + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) From e2555e5fedd8894e7f6208f5f5defb7695880cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Fri, 18 Jun 2021 11:49:35 +0100 Subject: [PATCH 24/33] fix paths of includes in clib.c With the module search path cleverly handled with different install.h configurations, the genstatic script inserted absolute paths into the generated clib.c file. This didn't fail on Windows CI as this is an in-source build. For out-of-source builds, it's crucial that clib.c can refer to both .c files in the source directory and those generated in the build directory. As a fix, the genstatic invocation now uses the -I flag. This patch also improves the handling of include paths to find the .c. files mentioned above by trimming down the scope of this property to clib.c only. Also, there is no need to manually tell the preprocessor where to look for generated .c, as they live relative to clib.c anyhow. --- CMakeLists.txt | 17 +++++++++++------ contrib/chibi-genstatic-helper.cmake | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e962c70a..d8524908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,6 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt AND NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE) endif() - # # Features # @@ -284,6 +283,17 @@ if (NOT BUILD_SHARED_LIBS) ${genstatic-helper} ${slds}) + # The generated file will #include both manually written files in + # the source directory as well as files generated by chibi-ffi in + # the build directory. The latter can be found without special flags, + # as they are relative to the clib.c, but the preprocessor needs + # help for the former. As only clib.c needs this flag, we set it + # as locally as possible, i.e., not as a target property. + set_source_files_properties(${clibout} + PROPERTIES + INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR}) + target_compile_definitions(libchibi-scheme PUBLIC SEXP_USE_STATIC_LIBS=1) @@ -291,11 +301,6 @@ if (NOT BUILD_SHARED_LIBS) target_sources(libchibi-scheme PUBLIC ${clibout}) - - target_include_directories(libchibi-common - INTERFACE - $<BUILD_INTERFACE:${stuboutdir}/..> - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) endif() # diff --git a/contrib/chibi-genstatic-helper.cmake b/contrib/chibi-genstatic-helper.cmake index abddb9d3..ff480ed4 100644 --- a/contrib/chibi-genstatic-helper.cmake +++ b/contrib/chibi-genstatic-helper.cmake @@ -16,7 +16,7 @@ if(NOT OUT) endif() execute_process( - COMMAND ${EXEC} ${GENSTATIC} --no-inline + COMMAND ${EXEC} -q -I ./lib ${GENSTATIC} --no-inline INPUT_FILE ${STUBS} OUTPUT_FILE ${OUT} RESULT_VARIABLE rr From 16b97a6e2618620e3f4d499fd8093f94e21b4789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Fri, 18 Jun 2021 11:55:07 +0100 Subject: [PATCH 25/33] reduce scope of clib.c within the chibi library --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8524908..b092c5d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,7 +299,7 @@ if (NOT BUILD_SHARED_LIBS) SEXP_USE_STATIC_LIBS=1) target_sources(libchibi-scheme - PUBLIC + PRIVATE ${clibout}) endif() From 699ffe18e9a860faeafa39d1e08bdd7af8ad9b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Tue, 6 Jul 2021 10:15:33 +0100 Subject: [PATCH 26/33] mostly revert module path handling introduced in 27c421e3 chibi/install.h is included in C source files, and providing a different install.h upon actual installation is inconsistent and dangerous. When working with a chibi executable within the build tree (i.e., not an installed executable), the CHIBI_MODULE_PATH environment tweak can be used to not always specify -I paths on the command line. --- CMakeLists.txt | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b092c5d5..f64ce6cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,16 +342,6 @@ string(JOIN ":" default_module_path ${CMAKE_INSTALL_FULL_DATAROOTDIR}/snow ${CMAKE_INSTALL_FULL_LIBDIR}/snow) -# This file will only be used during an installation (and renamed to install.h) -configure_file(include/chibi/install.h.in include/chibi/to-install.h) - -# This configuration is for development purpose: a chibi executable shall find -# both compiled libraries in its own build directory and scheme source libraries -# in the source directory. -string(JOIN ":" default_module_path - ${CMAKE_CURRENT_BINARY_DIR}/lib - ${CMAKE_CURRENT_SOURCE_DIR}/lib) - configure_file(include/chibi/install.h.in include/chibi/install.h) # @@ -368,12 +358,12 @@ set(chibi-scheme-tests foreach(e ${chibi-scheme-tests}) add_test(NAME "${e}" - COMMAND chibi-scheme tests/${e}.scm + COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib tests/${e}.scm WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() add_test(NAME r5rs-test - COMMAND chibi-scheme -xchibi tests/r5rs-tests.scm + COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib -xchibi tests/r5rs-tests.scm WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) file(GLOB_RECURSE srfi_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib @@ -418,7 +408,9 @@ foreach(e ${testlibs}) string(REGEX REPLACE "/" "_" testname ${e}) string(REGEX REPLACE "/" " " form ${e}) add_test(NAME "lib_${testname}" - COMMAND chibi-scheme -e "(import (${form}))" -e "(run-tests)" + COMMAND chibi-scheme -I ${CMAKE_CURRENT_BINARY_DIR}/lib + -e "(import (${form}))" + -e "(run-tests)" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endforeach() @@ -456,9 +448,8 @@ install(DIRECTORY include/chibi PATTERN "sexp-*.[hc]" EXCLUDE PATTERN "*.h.in" EXCLUDE) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/chibi/to-install.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/chibi - RENAME install.h) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/chibi/install.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/chibi) add_library(chibi::chibi ALIAS libchibi-scheme) From 0ae8069a07b91e4b7be022c84dbac377128f07df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Tue, 13 Jul 2021 11:39:38 +0100 Subject: [PATCH 27/33] fix repeated liblib prefix in library output name --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f64ce6cb..ad780572 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,7 @@ target_link_libraries(libchibi-scheme set_target_properties(libchibi-scheme PROPERTIES + PREFIX "" # It's liblibchibi-scheme otherwise SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR} VERSION ${CMAKE_PROJECT_VERSION}) From 287014e3d64a8219f5cc7e5453607f25f8cbe393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Tue, 20 Jul 2021 22:47:03 +0100 Subject: [PATCH 28/33] remove exclusion of weak-test, which works on unix --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad780572..75e5fedf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -373,9 +373,6 @@ file(GLOB_RECURSE srfi_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib file(GLOB_RECURSE chibi_scheme_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/lib CONFIGURE_DEPENDS lib/chibi/*-test.sld) -set(testexcludes - chibi/weak-test) - set(win32testexcludes # Excluded tests chibi/filesystem-test @@ -399,8 +396,6 @@ foreach(e ${srfi_tests} ${chibi_scheme_tests}) list(APPEND testlibs ${pth}/${nam}) endforeach() -list(REMOVE_ITEM testlibs ${testexcludes}) - if(WIN32) list(REMOVE_ITEM testlibs ${win32testexcludes}) endif() From a4a8ba0038218c23dd728c95e3d243f5c243dbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Tue, 13 Jul 2021 15:05:45 +0100 Subject: [PATCH 29/33] remove outdated platform restriction notice --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75e5fedf..536145d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,3 @@ -# -# FIXME: This CMakeLists.txt is only for Win32 platforms for now -# cmake_minimum_required(VERSION 3.12) From 5fcbb7c15cb3e73e404c591b76f097f366cb47c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Tue, 20 Jul 2021 22:49:30 +0100 Subject: [PATCH 30/33] prefer consistent low caps command names --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 536145d5..ceb48994 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ include(GNUInstallDirs) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -SET(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING +set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Build type: None, Debug, Release, RelWithDebInfo, MinSizeRel, or Sanitizer." FORCE) if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt AND NOT CMAKE_BUILD_TYPE) From 32e7f0bf7e2484ed648d128846d5377c47ee6dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 21 Jul 2021 18:28:45 +0100 Subject: [PATCH 31/33] remove unnecessary left-over flags --- contrib/chibi-genstatic-helper.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/chibi-genstatic-helper.cmake b/contrib/chibi-genstatic-helper.cmake index ff480ed4..abddb9d3 100644 --- a/contrib/chibi-genstatic-helper.cmake +++ b/contrib/chibi-genstatic-helper.cmake @@ -16,7 +16,7 @@ if(NOT OUT) endif() execute_process( - COMMAND ${EXEC} -q -I ./lib ${GENSTATIC} --no-inline + COMMAND ${EXEC} ${GENSTATIC} --no-inline INPUT_FILE ${STUBS} OUTPUT_FILE ${OUT} RESULT_VARIABLE rr From 47a6e7fd3c92e464e4b3109190d67ddefbe589f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 21 Jul 2021 18:29:03 +0100 Subject: [PATCH 32/33] streamline library alias name --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ceb48994..69caafb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -444,7 +444,7 @@ install(DIRECTORY include/chibi install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/chibi/install.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/chibi) -add_library(chibi::chibi ALIAS libchibi-scheme) +add_library(chibi::libchibi-scheme ALIAS libchibi-scheme) install(TARGETS libchibi-scheme LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} From 527101a1c2e492dc08c7aaa016f87a055d16a2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20B=C3=B6ger?= <mail@lboeger.de> Date: Wed, 21 Jul 2021 18:32:23 +0100 Subject: [PATCH 33/33] leave the default module path empty on windows --- CMakeLists.txt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69caafb0..d45416eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -333,12 +333,17 @@ else() set(platform "unix") endif() - -string(JOIN ":" default_module_path - ${CMAKE_INSTALL_FULL_DATAROOTDIR}/chibi - ${CMAKE_INSTALL_FULL_LIBDIR}/chibi - ${CMAKE_INSTALL_FULL_DATAROOTDIR}/snow - ${CMAKE_INSTALL_FULL_LIBDIR}/snow) +if(WIN32) + # Leave this empty for now, as the default GNU install directories won't + # help on Windows. + set(default_module_path "") +else() + string(JOIN ":" default_module_path + ${CMAKE_INSTALL_FULL_DATAROOTDIR}/chibi + ${CMAKE_INSTALL_FULL_LIBDIR}/chibi + ${CMAKE_INSTALL_FULL_DATAROOTDIR}/snow + ${CMAKE_INSTALL_FULL_LIBDIR}/snow) +endif() configure_file(include/chibi/install.h.in include/chibi/install.h)