From 4256fe30a6eee88983bbe39b606a793a47b96ec0 Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:47:20 -0400 Subject: [PATCH 1/4] CMake support (initial) --- CMakeLists.txt | 165 ++++++++++++++++++++++++++ cmake/BundleIcon.icns | Bin 0 -> 33452 bytes cmake/CTestConfig.cmake | 7 ++ cmake/Config.cmake.in | 4 + cmake/CustomVolumeIcon.icns | Bin 0 -> 37827 bytes cmake/Info.plist | 14 +++ cmake/MultiCPackConfig.cmake | 6 + cmake/README.txt | 5 + cmake/Welcome.txt | 1 + cmake/config.h.in | 9 ++ cmake/modules/AcquireGoogleTest.cmake | 11 ++ cmake/modules/EnsureSymbol.cmake | 41 +++++++ include/CMakeLists.txt | 50 ++++++++ include/bc.h | 12 +- include/dc.h | 2 +- include/history.h | 10 +- include/read.h | 3 +- src/CMakeLists.txt | 101 ++++++++++++++++ 18 files changed, 429 insertions(+), 12 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/BundleIcon.icns create mode 100644 cmake/CTestConfig.cmake create mode 100644 cmake/Config.cmake.in create mode 100644 cmake/CustomVolumeIcon.icns create mode 100644 cmake/Info.plist create mode 100644 cmake/MultiCPackConfig.cmake create mode 100644 cmake/README.txt create mode 100644 cmake/Welcome.txt create mode 100644 cmake/config.h.in create mode 100644 cmake/modules/AcquireGoogleTest.cmake create mode 100644 cmake/modules/EnsureSymbol.cmake create mode 100644 include/CMakeLists.txt create mode 100644 src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..cc223528 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,165 @@ +cmake_minimum_required(VERSION 3.11) + +project(bc VERSION 0.0.1 LANGUAGES C) + +set(CMAKE_C_STANDARD 90) +set(CMAKE_C_STANDARD_REQUIRED ON) + +add_library("${PROJECT_NAME}_compiler_flags" INTERFACE) + +if (NOT DEFINED MSVC_VERSION + OR MSVC_VERSION STRGREATER "1900" # 2015 + OR NOT (CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")) + target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_${CMAKE_C_STANDARD}") +elseif ((MSVC_VERSION STRLESS_EQUAL "1900" + OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom" + OR CYGWIN) + AND NOT EXISTS "${CMAKE_BINARY_DIR}/c89stringutils_export.h") + file(COPY "${CMAKE_SOURCE_DIR}/c89stringutils/c89stringutils_export_pregen.h" + DESTINATION "${CMAKE_BINARY_DIR}") + file(RENAME "${CMAKE_BINARY_DIR}/c89stringutils_export_pregen.h" + "${CMAKE_BINARY_DIR}/c89stringutils_export.h") +endif () +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15") + # add compiler warning flags just when building this project via + # the BUILD_INTERFACE genex + set(gcc_like "$") + set(msvc "$") + target_compile_options( + "${PROJECT_NAME}_compiler_flags" + INTERFACE + "$<${gcc_like}:$>" + "$<${msvc}:$>" + ) +endif (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15") +# Set the build directories +if (CMAKE_SYSTEM_NAME STREQUAL "Windows" + OR CMAKE_SYSTEM_NAME STREQUAL "CYGWIN" + OR CMAKE_SYSTEM_NAME MATCHES "MINGW.*") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") +else () + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") +endif () + +if (CMAKE_GENERATOR MATCHES "Visual Studio 8 2005.*") + set(COMPILE_LANG_AND_ID "MSVC") +else () + set(CMAKE_C_VISIBILITY_PRESET hidden) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) + set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) + + target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_${CMAKE_C_STANDARD}") + + # add compiler warning flags just when building this project via + # the BUILD_INTERFACE genex + set(gcc_like "$") + set(msvc "$") + target_compile_options( + "${PROJECT_NAME}_compiler_flags" + INTERFACE + "$<${gcc_like}:$>" + "$<${msvc}:$>" + ) +endif () + +if (MSVC OR __COMPILER_MSVC OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") +else () + include("${CMAKE_SOURCE_DIR}/cmake/modules/EnsureSymbol.cmake") + ensure_symbol( + TARGET "${PROJECT_NAME}_compiler_flags" + SYMBOL "asprintf" + INCLUDES "stdio.h" + DEFINITIONS "_GNU_SOURCE" "_BSD_SOURCE" + ) +endif (MSVC OR __COMPILER_MSVC OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") +if (DEFINED HAVE_ASPRINTF) + set(CMAKE_C_EXTENSIONS ON) + add_compile_definitions(HAVE_ASPRINTF) +endif (DEFINED HAVE_ASPRINTF) + +# configure a header file to pass the version number only +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in" + "${PROJECT_NAME}Config.h" +) + +#=============================================================================== +# 4. ADD SUB-TARGETS +# Doing this at the end so that all definitions and link/include paths are +# available for the sub-projects. +#=============================================================================== +add_subdirectory("include") +add_subdirectory("src") + +########### +# Install # +########### + +include(GNUInstallDirs) + +install( + FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) +include(InstallRequiredSystemLibraries) +set(CPACK_BUNDLE_NAME "${PROJECT_NAME}") +set(CPACK_PACKAGE_VENDOR "SamuelMarks") +set(CPACK_PACKAGE_DESCRIPTION "Frontend for C, concentrating on: generation from code; single-file analysis; modification; and emission (to C code).") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") +if (APPLE) + set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist") + set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist") + set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CustomVolumeIcon.icns") +endif (APPLE) +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.md") +set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/cmake/README.txt") +set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Welcome.txt") +set(CPACK_PACKAGE_CONTACT "https://github.com/gavinhoward/bc") + +include(CPack) +include(CMakePackageConfigHelpers) + +# generate the config file that is includes the exports +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +# generate the version file for the config file +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}" + COMPATIBILITY AnyNewerVersion +) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}") + + +### target install + +set(installable_libs # "${EXEC_NAME}" + "${LIBRARY_NAME}") +if (TARGET "${DEPENDANT_LIBRARY}") + list(APPEND installable_libs "${DEPENDANT_LIBRARY}") +endif () +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13") + list(APPEND installable_libs "${PROJECT_NAME}_compiler_flags") +endif () +install(TARGETS ${installable_libs} + EXPORT "${LIBRARY_NAME}Targets" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +install(EXPORT "${LIBRARY_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}") + +install(FILES ${Header_Files} #"${_export_file}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/cmake/BundleIcon.icns b/cmake/BundleIcon.icns new file mode 100644 index 0000000000000000000000000000000000000000..8808dd62db64540292417e8865bdf627aaf8792e GIT binary patch literal 33452 zcmeHOdvsOhmH+ND3E@$o&e9H@%&P5L{1ctwU<;)Zs`WM6I?kfg89Hmm+L^0ZX+AG~=i2H|SAQD9-)Q>fD~)-u>8^1*OsmxG8t_@661U4VtWdGrGhpEVfg-oZ zqz$XkEe8CC%M4iq1#V%=&5)H3X~1xsA&B#&7*PI@uyUoj)9l2a!x{)kozrJp0Vw@$ zC(r}JVVM4q+Zu4Y%>v;y{8lLB9w;$fKH!xNh!7DoiI`z9F<~+>VJKokm_#gKI3Z$Q ze#nScuHh08YE~x6ZC2QG7+~cz4WHii!!JArk@6Qm@Z-~z0+ypwGxAy%0&d!jEZRb> zBqPgTEL@=DD>WQUX61qvKSB=E#n69L1QCB+6=6ZlKJ7*x5wp*`VS|``y{ipk_QShu z5VIe-O9nCf(Yu59?z#OtxF&QQ{MhW|m+O)c^h*1HUo)->L9eW9{L1-M2zsrCPkMzy zetIFio%C{rLYL^377BepuNk4xReELd>sn4IbZvDg^eO!>>_7jc`CtARUDNI_?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bp;ez?)L93 zo{kGM{1j%0xrMkFprDXTg07`cvtbZ;J^t@$$Mh%LhH$jnUhZdEs9 zTuq_#ZFP+R@=#T*`rJ8Q`k**}@j`=C$O>>mL9U@-*8!bu-00XJKDJ|lGBOaE{mJkj8U4wqfLQ;jt$^6< zr#b_%*-y3q*yyLa0*3ORx(XO7`>D*pP}xtV|DmFv$_g0He`+dVxa_AY1H)xMRsM&I zeyS>9B>%~;fRVDFiVTdD{Z#lLDf+3XfYJOXw*p4XezG$#TK1Fef3)Z)y8_1IKY0}} zmh2}p17pd4GX0Mw`pK+-vHDL=1&lTO$;!Z3v!5*gV~u{YDj**JiLZcovY(6$#FPDG z_>U+0$*6#M{U^2p;>~`dGZ1g~6YW3V=qI`Y#^XP66)>LcCo%)$$$ldJk0<(xtbp?gwiM53RF3Ye(>iB-Tvvp>-c zOf>rw^*_<*PqYFO;eY%UkcjM0Bm;@a{zUvIBKi}lfJFHpUj-y8`{T_(qOw0;|A~tJ zcq<^0{^PHJL}q_H8AxRI$KyYd(H~C*B-(#`6_Duc$D4sfXFp#5iH?4}6_5=7W3PZ@ zWIvt^BqRIr_)kXk+`e{%{#cRrZJTpQ`8&R{^Q?Kez%?nf;+6kjm_n|JVqmGWz5{_BS)1`RAyl?mhZ9 tOR28E*!-vZ`iu211pSsWm4C6nTBP5Srt)v{ezlppUr2uD>HmEM{tp8ay}tke literal 0 HcmV?d00001 diff --git a/cmake/CTestConfig.cmake b/cmake/CTestConfig.cmake new file mode 100644 index 00000000..e992a765 --- /dev/null +++ b/cmake/CTestConfig.cmake @@ -0,0 +1,7 @@ +set(CTEST_PROJECT_NAME "bc_portable") +set(CTEST_NIGHTLY_START_TIME "00:00:00 EST") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "my.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=bc_portable") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 00000000..618b7325 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,4 @@ + +@PACKAGE_INIT@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/bc_portableTargets.cmake" ) diff --git a/cmake/CustomVolumeIcon.icns b/cmake/CustomVolumeIcon.icns new file mode 100644 index 0000000000000000000000000000000000000000..3862a51917954ff9c92cfe8e7469c4b12525796b GIT binary patch literal 37827 zcmeI4`EOgj0}mY0!jd6Q+W*1lQ$W=SNqZ(g)myGV)@DN@|u?K$uAiIhajo&-VC&KtnM zNbj6`&pG#=``-J!ul?Q+fA;gFq`aQ@e*U$;NJ=`^c8rj4dN4_1$jM#P%JS;k`li)p z-+IN6k5}5A)-C(C)8*dv4u=Ste+oZ4wp}}(-N1y8kZF@^%i+Wyz0%YUAtMtzcKNE$ zPoCKc8F;Zne+&f3{01RCOFL-n3j~8?d5Ms&O*j296e62*B-r6_!%Y4_FdQb1XJq%! zIz1jQSck$AA)aaC=yb^Qx!v%4=NMTZB$9z>rHSymxvxoV(KngL0_(jO|LYY0f$r4L z9vB1Os)vS0$4l-Hl3zbf_mOGBRo`bx)8`LDUWwC$!u>9$DX-UOSWO?S=5HX)pa125 zzMqt&(UZ^lfA9Sin>f|RkR&M&{uqeHzQJs=7S_tz*e%U=h$ml`$au~C%enc5#aBzq zE70H@7K_!k1@e`L-FA!BYO`(OMW@pR zn-aRfQ{yBOOTH7nJLG_oB3I>$p50w|VI|_ZISxZ_DbC=Fmwn;pSM>T;!85xR zFT=brv3!~FeMCB@>Gjo{i*_75=CaS{_mlon5{6TYJS$vtY{^lhH%11Rp$SL&(LYQ^ z?py3|UeUpo%fSGd?V#8DO1B)!;L2qtc#}+v zhrJo;OQd-PuiJ0Ga64hKAZr{v05kt-I4ntF((w$huNN+P=yK7^L7beCz8WU|<5<3z z_clB+-tuKu`ol08hEtW0@nV~M?=llS2F|SXM-cu@7hWE$aCvvJ+OnS{i6m7bi*0zR zwU)6Y%e#VcByBTJ-j%ZB+?{X0J4|y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Nnj#wK9;y39Vho3R6lV&DF|Z>1jcyM*t|5-_mx*xv{dM~c!e10u$HBmBZv3mT z@nCf3VGIoafZ0J?s@euyMfRJj$bQ|RtYP7;5*79I^9r8SuZ6&ovf=8X5c}6w{T`d2 zn`33=FCgH;1wwRrRl`{{5X(|9&92JY6a8^s1;BvpjJSwfLZ~y0%`@+3aAxOE1*_Dt$(s+eu0P3)=f^qW}N^ literal 0 HcmV?d00001 diff --git a/cmake/Info.plist b/cmake/Info.plist new file mode 100644 index 00000000..e5a7d004 --- /dev/null +++ b/cmake/Info.plist @@ -0,0 +1,14 @@ + + + + + CFBundleExecutable + BundleGeneratorTest + CFBundleIconFile + BundleGeneratorTest.icns + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + + diff --git a/cmake/MultiCPackConfig.cmake b/cmake/MultiCPackConfig.cmake new file mode 100644 index 00000000..6b6645c7 --- /dev/null +++ b/cmake/MultiCPackConfig.cmake @@ -0,0 +1,6 @@ +include("release/CPackConfig.cmake") + +set(CPACK_INSTALL_CMAKE_PROJECTS + "debug;bc_portable;ALL;/" + "release;bc_portable;ALL;/" +) diff --git a/cmake/README.txt b/cmake/README.txt new file mode 100644 index 00000000..27a5e5aa --- /dev/null +++ b/cmake/README.txt @@ -0,0 +1,5 @@ +bc + +This is an implementation of the [POSIX `bc` calculator][12] that implements +[GNU `bc`][1] extensions, as well as the period (`.`) extension for the BSD +flavor of `bc`. diff --git a/cmake/Welcome.txt b/cmake/Welcome.txt new file mode 100644 index 00000000..657dc46c --- /dev/null +++ b/cmake/Welcome.txt @@ -0,0 +1 @@ +This installs bc. diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..ff3a0917 --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,9 @@ +#ifndef BC_CONFIG_H +#define BC_CONFIG_H + +#define BC_VERSION_MAJOR @bc_portable_VERSION_MAJOR@ +#define BC_VERSION_MINOR @bc_portable_VERSION_MINOR@ +#define BC_VERSION_PATCH @bc_portable_VERSION_PATCH@ +#define BC_VERSION "@bc_portable_VERSION@" + +#endif /* !BC_CONFIG_H */ diff --git a/cmake/modules/AcquireGoogleTest.cmake b/cmake/modules/AcquireGoogleTest.cmake new file mode 100644 index 00000000..d25a5dd2 --- /dev/null +++ b/cmake/modules/AcquireGoogleTest.cmake @@ -0,0 +1,11 @@ +macro (acquire_google_test) + include(FetchContent) + FetchContent_Declare( + googletest + # Specify the commit you depend on and update it regularly. + URL https://github.com/google/googletest/archive/c9461a9b55ba954df0489bab6420eb297bed846b.zip + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) +endmacro (acquire_google_test) diff --git a/cmake/modules/EnsureSymbol.cmake b/cmake/modules/EnsureSymbol.cmake new file mode 100644 index 00000000..36508229 --- /dev/null +++ b/cmake/modules/EnsureSymbol.cmake @@ -0,0 +1,41 @@ +include(CheckSymbolExists) + +function(ensure_symbol) + cmake_parse_arguments(PARSE_ARGV 0 ARG "PUBLIC" "TARGET;SYMBOL" "INCLUDES;DEFINITIONS") + + # Determine visibility for symbols that need to be added + get_property(type TARGET "${ARG_TARGET}" PROPERTY TYPE) + if (type STREQUAL "INTERFACE_LIBRARY") + set(visibility INTERFACE) + elseif (ARG_PUBLIC) + set(visibility PUBLIC) + else () + set(visibility PRIVATE) + endif () + + # The base name of the cache variables to create + string(TOUPPER "HAVE_${ARG_SYMBOL}" var_name) + message(STATUS "symbol is ${var_name}") + + # Check the base version + check_symbol_exists("${ARG_SYMBOL}" "${ARG_INCLUDES}" "${var_name}") + + if (${var_name}) + return () + endif () + + # Otherwise, start trying alternatives + foreach (def IN LISTS ARG_DEFINITIONS) + set(local_name "${var_name}${def}") + + set(CMAKE_REQUIRED_DEFINITIONS "-D${def}") + check_symbol_exists("${ARG_SYMBOL}" "${ARG_INCLUDES}" "${local_name}") + + if (${local_name}) + target_compile_definitions("${ARG_TARGET}" "${visibility}" "${def}") + return() + endif () + endforeach () + + message(FATAL_ERROR "Could not ensure ${ARG_TARGET} can use ${ARG_SYMBOL}") +endfunction() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 00000000..52ee7172 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,50 @@ +set(LIBRARY_NAME "${PROJECT_NAME}_includes") + +set(Header_Files + "args.h" + "bc.h" + "bcl.h" + "dc.h" + "file.h" + "history.h" + "lang.h" + "lex.h" + "library.h" + "num.h" + "opt.h" + "parse.h" + "program.h" + "rand.h" + "read.h" + "status.h" + "vector.h" + "version.h" + "vm.h" +) +source_group("Header Files" FILES "${Header_Files}") +add_library("${LIBRARY_NAME}" INTERFACE "${Header_Files}") + +include(GNUInstallDirs) +target_include_directories( + "${LIBRARY_NAME}" + INTERFACE + "$" + "$" + "$" +) + +if (NOT DEFINED HAVE_ASPRINTF) + find_package(c89stringutils CONFIG REQUIRED) + target_link_libraries("${LIBRARY_NAME}" INTERFACE c89stringutils c89stringutils_compiler_flags) +endif (NOT DEFINED HAVE_ASPRINTF) + +target_link_libraries( + "${LIBRARY_NAME}" + INTERFACE + "${PROJECT_NAME}_compiler_flags" +) + +set_target_properties("${LIBRARY_NAME}" PROPERTIES LINKER_LANGUAGE C) + +install(FILES ${Header_Files} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/include/bc.h b/include/bc.h index 73a85aa4..0ce1da99 100644 --- a/include/bc.h +++ b/include/bc.h @@ -49,19 +49,19 @@ * The main function for bc. It just sets variables and passes its arguments * through to @a bc_vm_boot(). */ -void +BC_EXPORT void bc_main(int argc, char* argv[]); // These are references to the help text, the library text, and the "filename" // for the library. extern const char bc_help[]; -extern const char bc_lib[]; -extern const char* bc_lib_name; +extern BC_EXPORT const char bc_lib[]; +extern BC_EXPORT const char* bc_lib_name; // These are references to the second math library and its "filename." #if BC_ENABLE_EXTRA_MATH -extern const char bc_lib2[]; -extern const char* bc_lib2_name; +extern BC_EXPORT const char bc_lib2[]; +extern BC_EXPORT const char* bc_lib2_name; #endif // BC_ENABLE_EXTRA_MATH /** @@ -411,7 +411,7 @@ bc_parse_parse(BcParse* p); * function definition, we know we can add an empty else clause. * @param p The parser. */ -void +BC_EXPORT void bc_parse_endif(BcParse* p); /// References to the signal message and its length. diff --git a/include/dc.h b/include/dc.h index 9a603c26..41afb6a5 100644 --- a/include/dc.h +++ b/include/dc.h @@ -46,7 +46,7 @@ * The main function for dc. It just sets variables and passes its arguments * through to @a bc_vm_boot(). */ -void +BC_EXPORT void dc_main(int argc, char* argv[]); // A reference to the dc help text. diff --git a/include/history.h b/include/history.h index 19c5a0fe..f01c9fcc 100644 --- a/include/history.h +++ b/include/history.h @@ -79,6 +79,8 @@ #ifndef BC_HISTORY_H #define BC_HISTORY_H +#include "bc_export.h" + // These must come before the #if BC_ENABLE_LINE_LIB below because status.h // defines it. #include @@ -340,7 +342,7 @@ typedef struct BcHistory * Frees strings used by history. * @param str The string to free. */ -void +BC_EXPORT void bc_history_string_free(void* str); // A list of terminals that don't work. @@ -393,21 +395,21 @@ bc_history_printKeyCodes(BcHistory* h); * leave the terminal in raw mode or in some other half-baked * state. */ -BcStatus +BC_EXPORT BcStatus bc_history_line(BcHistory* h, BcVec* vec, const char* prompt); /** * Initialize history data. * @param h The struct to initialize. */ -void +BC_EXPORT void bc_history_init(BcHistory* h); /** * Free history data (and recook the terminal). * @param h The struct to free. */ -void +BC_EXPORT void bc_history_free(BcHistory* h); #endif // BC_ENABLE_HISTORY diff --git a/include/read.h b/include/read.h index 867dcd74..50e34485 100644 --- a/include/read.h +++ b/include/read.h @@ -40,6 +40,7 @@ #include #include +#include "bc_export.h" /** * Returns true if @a c is a non-ASCII (invalid) char. @@ -53,7 +54,7 @@ * @param vec The vector to put the stdin data into. * @param prompt The prompt to print, if desired. */ -BcStatus +BC_EXPORT BcStatus bc_read_line(BcVec* vec, const char* prompt); /** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..6beee4dd --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,101 @@ +########### +# Library # +########### + +include(CheckIncludeFile) + +set(LIBRARY_NAME "${PROJECT_NAME}") + +set(Source_Files + "args.c" + "bc.c" + "bc_lex.c" + "bc_parse.c" + "data.c" + "dc.c" + "dc_lex.c" + "dc_parse.c" + "file.c" + "history.c" + "lang.c" + "lex.c" + "library.c" + "main.c" + "num.c" + "opt.c" + "parse.c" + "program.c" + "rand.c" + "read.c" + "vector.c" + "vm.c" +) +source_group("Source Files" FILES "${Source_Files}") + +add_library("${LIBRARY_NAME}" "${Source_Files}") + +include(GNUInstallDirs) + +target_link_libraries( + "${LIBRARY_NAME}" + PRIVATE + "${PROJECT_NAME}_compiler_flags" +) + +target_link_libraries( + "${LIBRARY_NAME}" + PUBLIC + "${PROJECT_NAME}_includes" +) + +set_target_properties("${LIBRARY_NAME}" PROPERTIES LINKER_LANGUAGE C) + + +####### +# CLI # +####### + +set(EXEC_NAME "${PROJECT_NAME}_cli") + +set(Cli_Source_Files "main.c") +source_group("${EXEC_NAME} Source Files" FILES "${Cli_Source_Files}") + +add_executable("${EXEC_NAME}" "${Cli_Source_Files}") + +target_link_libraries("${EXEC_NAME}" PRIVATE "${LIBRARY_NAME}") +set_target_properties("${EXEC_NAME}" PROPERTIES LINKER_LANGUAGE C) + +################# +# Install rules # +################# + +include(GNUInstallDirs) + +# setup the version numbering +set_property(TARGET "${LIBRARY_NAME}" PROPERTY VERSION "${${PROJECT_NAME}_VERSION}") +set_property(TARGET "${LIBRARY_NAME}" PROPERTY SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}") + +set(installable_libs # "${EXEC_NAME}" + "${LIBRARY_NAME}_includes" + "${LIBRARY_NAME}") +if (TARGET "${DEPENDANT_LIBRARY}") + list(APPEND installable_libs "${DEPENDANT_LIBRARY}") +endif () +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13") + list(APPEND installable_libs "${PROJECT_NAME}_compiler_flags") +endif () +install(TARGETS ${installable_libs} + EXPORT "${LIBRARY_NAME}Targets" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +install(EXPORT "${LIBRARY_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}") + + +include(GenerateExportHeader) +set(_export_file "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}_export.h") +generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}") + +message("_export_file = ${_export_file}") +install(FILES "${_export_file}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") From 63e687a593ca72430a23216ab35eb897a4677b36 Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Thu, 17 Aug 2023 16:06:53 -0400 Subject: [PATCH 2/4] Improve CMake suppoprt and remove extraneous code & files --- CMakeLists.txt | 43 ++++----------------------- cmake/CTestConfig.cmake | 4 +-- cmake/Config.cmake.in | 2 +- cmake/MultiCPackConfig.cmake | 4 +-- cmake/config.h.in | 10 ++++--- cmake/modules/AcquireGoogleTest.cmake | 11 ------- cmake/modules/EnsureSymbol.cmake | 41 ------------------------- include/CMakeLists.txt | 5 ---- include/vm.h | 4 +-- src/CMakeLists.txt | 12 +++++--- 10 files changed, 26 insertions(+), 110 deletions(-) delete mode 100644 cmake/modules/AcquireGoogleTest.cmake delete mode 100644 cmake/modules/EnsureSymbol.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index cc223528..7422e3c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,22 +66,10 @@ else () ) endif () -if (MSVC OR __COMPILER_MSVC OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") -else () - include("${CMAKE_SOURCE_DIR}/cmake/modules/EnsureSymbol.cmake") - ensure_symbol( - TARGET "${PROJECT_NAME}_compiler_flags" - SYMBOL "asprintf" - INCLUDES "stdio.h" - DEFINITIONS "_GNU_SOURCE" "_BSD_SOURCE" - ) -endif (MSVC OR __COMPILER_MSVC OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") -if (DEFINED HAVE_ASPRINTF) - set(CMAKE_C_EXTENSIONS ON) - add_compile_definitions(HAVE_ASPRINTF) -endif (DEFINED HAVE_ASPRINTF) +include(CheckSymbolExists) +check_symbol_exists(BCryptGenRandom "windows.h;bcrypt.h" HAVE_BCRYPT) -# configure a header file to pass the version number only +# configure a header file to pass the version number and exist flags only configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in" "${PROJECT_NAME}Config.h" @@ -107,8 +95,8 @@ install( ) include(InstallRequiredSystemLibraries) set(CPACK_BUNDLE_NAME "${PROJECT_NAME}") -set(CPACK_PACKAGE_VENDOR "SamuelMarks") -set(CPACK_PACKAGE_DESCRIPTION "Frontend for C, concentrating on: generation from code; single-file analysis; modification; and emission (to C code).") +set(CPACK_PACKAGE_VENDOR "Gavin Howard") +set(CPACK_PACKAGE_DESCRIPTION "This is an implementation of the POSIX `bc` calculator") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") if (APPLE) set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist") @@ -142,24 +130,3 @@ write_basic_package_version_file( ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}") - - -### target install - -set(installable_libs # "${EXEC_NAME}" - "${LIBRARY_NAME}") -if (TARGET "${DEPENDANT_LIBRARY}") - list(APPEND installable_libs "${DEPENDANT_LIBRARY}") -endif () -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13") - list(APPEND installable_libs "${PROJECT_NAME}_compiler_flags") -endif () -install(TARGETS ${installable_libs} - EXPORT "${LIBRARY_NAME}Targets" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") -install(EXPORT "${LIBRARY_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}") - -install(FILES ${Header_Files} #"${_export_file}" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/cmake/CTestConfig.cmake b/cmake/CTestConfig.cmake index e992a765..507cc151 100644 --- a/cmake/CTestConfig.cmake +++ b/cmake/CTestConfig.cmake @@ -1,7 +1,7 @@ -set(CTEST_PROJECT_NAME "bc_portable") +set(CTEST_PROJECT_NAME "bc") set(CTEST_NIGHTLY_START_TIME "00:00:00 EST") set(CTEST_DROP_METHOD "http") set(CTEST_DROP_SITE "my.cdash.org") -set(CTEST_DROP_LOCATION "/submit.php?project=bc_portable") +set(CTEST_DROP_LOCATION "/submit.php?project=bc") set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 618b7325..2b4310fe 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -1,4 +1,4 @@ @PACKAGE_INIT@ -include ( "${CMAKE_CURRENT_LIST_DIR}/bc_portableTargets.cmake" ) +include ( "${CMAKE_CURRENT_LIST_DIR}/bcTargets.cmake" ) diff --git a/cmake/MultiCPackConfig.cmake b/cmake/MultiCPackConfig.cmake index 6b6645c7..2a5a8e16 100644 --- a/cmake/MultiCPackConfig.cmake +++ b/cmake/MultiCPackConfig.cmake @@ -1,6 +1,6 @@ include("release/CPackConfig.cmake") set(CPACK_INSTALL_CMAKE_PROJECTS - "debug;bc_portable;ALL;/" - "release;bc_portable;ALL;/" + "debug;bc;ALL;/" + "release;bc;ALL;/" ) diff --git a/cmake/config.h.in b/cmake/config.h.in index ff3a0917..76313c06 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -1,9 +1,11 @@ #ifndef BC_CONFIG_H #define BC_CONFIG_H -#define BC_VERSION_MAJOR @bc_portable_VERSION_MAJOR@ -#define BC_VERSION_MINOR @bc_portable_VERSION_MINOR@ -#define BC_VERSION_PATCH @bc_portable_VERSION_PATCH@ -#define BC_VERSION "@bc_portable_VERSION@" +#define BC_VERSION_MAJOR @bc_VERSION_MAJOR@ +#define BC_VERSION_MINOR @bc_VERSION_MINOR@ +#define BC_VERSION_PATCH @bc_VERSION_PATCH@ +#define BC_VERSION "@bc_VERSION@" +#cmakedefine HAVE_BCRYPT + #endif /* !BC_CONFIG_H */ diff --git a/cmake/modules/AcquireGoogleTest.cmake b/cmake/modules/AcquireGoogleTest.cmake deleted file mode 100644 index d25a5dd2..00000000 --- a/cmake/modules/AcquireGoogleTest.cmake +++ /dev/null @@ -1,11 +0,0 @@ -macro (acquire_google_test) - include(FetchContent) - FetchContent_Declare( - googletest - # Specify the commit you depend on and update it regularly. - URL https://github.com/google/googletest/archive/c9461a9b55ba954df0489bab6420eb297bed846b.zip - ) - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) -endmacro (acquire_google_test) diff --git a/cmake/modules/EnsureSymbol.cmake b/cmake/modules/EnsureSymbol.cmake deleted file mode 100644 index 36508229..00000000 --- a/cmake/modules/EnsureSymbol.cmake +++ /dev/null @@ -1,41 +0,0 @@ -include(CheckSymbolExists) - -function(ensure_symbol) - cmake_parse_arguments(PARSE_ARGV 0 ARG "PUBLIC" "TARGET;SYMBOL" "INCLUDES;DEFINITIONS") - - # Determine visibility for symbols that need to be added - get_property(type TARGET "${ARG_TARGET}" PROPERTY TYPE) - if (type STREQUAL "INTERFACE_LIBRARY") - set(visibility INTERFACE) - elseif (ARG_PUBLIC) - set(visibility PUBLIC) - else () - set(visibility PRIVATE) - endif () - - # The base name of the cache variables to create - string(TOUPPER "HAVE_${ARG_SYMBOL}" var_name) - message(STATUS "symbol is ${var_name}") - - # Check the base version - check_symbol_exists("${ARG_SYMBOL}" "${ARG_INCLUDES}" "${var_name}") - - if (${var_name}) - return () - endif () - - # Otherwise, start trying alternatives - foreach (def IN LISTS ARG_DEFINITIONS) - set(local_name "${var_name}${def}") - - set(CMAKE_REQUIRED_DEFINITIONS "-D${def}") - check_symbol_exists("${ARG_SYMBOL}" "${ARG_INCLUDES}" "${local_name}") - - if (${local_name}) - target_compile_definitions("${ARG_TARGET}" "${visibility}" "${def}") - return() - endif () - endforeach () - - message(FATAL_ERROR "Could not ensure ${ARG_TARGET} can use ${ARG_SYMBOL}") -endfunction() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 52ee7172..11420184 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -33,11 +33,6 @@ target_include_directories( "$" ) -if (NOT DEFINED HAVE_ASPRINTF) - find_package(c89stringutils CONFIG REQUIRED) - target_link_libraries("${LIBRARY_NAME}" INTERFACE c89stringutils c89stringutils_compiler_flags) -endif (NOT DEFINED HAVE_ASPRINTF) - target_link_libraries( "${LIBRARY_NAME}" INTERFACE diff --git a/include/vm.h b/include/vm.h index c56cc8e7..86093ead 100644 --- a/include/vm.h +++ b/include/vm.h @@ -792,7 +792,7 @@ bc_vm_info(const char* const help); * @param argc The count of arguments. * @param argv The argument array. */ -void +BC_EXPORT void bc_vm_boot(int argc, char* argv[]); /** @@ -805,7 +805,7 @@ bc_vm_init(void); /** * Frees the BcVm global. */ -void +BC_EXPORT void bc_vm_shutdown(void); /** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6beee4dd..0adb326f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,6 +48,11 @@ target_link_libraries( "${PROJECT_NAME}_includes" ) +#if (HAVE_BCRYPT) +if (WIN32) + target_link_libraries("${LIBRARY_NAME}" PUBLIC bcrypt.lib) +endif () + set_target_properties("${LIBRARY_NAME}" PROPERTIES LINKER_LANGUAGE C) @@ -62,7 +67,8 @@ source_group("${EXEC_NAME} Source Files" FILES "${Cli_Source_Files}") add_executable("${EXEC_NAME}" "${Cli_Source_Files}") -target_link_libraries("${EXEC_NAME}" PRIVATE "${LIBRARY_NAME}") +target_link_libraries("${EXEC_NAME}" PUBLIC "${LIBRARY_NAME}") + set_target_properties("${EXEC_NAME}" PROPERTIES LINKER_LANGUAGE C) ################# @@ -75,7 +81,7 @@ include(GNUInstallDirs) set_property(TARGET "${LIBRARY_NAME}" PROPERTY VERSION "${${PROJECT_NAME}_VERSION}") set_property(TARGET "${LIBRARY_NAME}" PROPERTY SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}") -set(installable_libs # "${EXEC_NAME}" +set(installable_libs "${LIBRARY_NAME}_includes" "${LIBRARY_NAME}") if (TARGET "${DEPENDANT_LIBRARY}") @@ -91,11 +97,9 @@ install(TARGETS ${installable_libs} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") install(EXPORT "${LIBRARY_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}") - include(GenerateExportHeader) set(_export_file "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}_export.h") generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}") -message("_export_file = ${_export_file}") install(FILES "${_export_file}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") From a2e95a6e697fa9d6557a16c17ad6bf8d048b5bd3 Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Fri, 18 Aug 2023 17:02:52 -0400 Subject: [PATCH 3/4] Improve CMake support --- .gitignore | 3 +++ CMakeLists.txt | 11 +-------- bcl.pc.in | 2 +- include/CMakeLists.txt | 45 ----------------------------------- src/CMakeLists.txt | 54 +++++++++++++++++++++++++++++------------- 5 files changed, 43 insertions(+), 72 deletions(-) delete mode 100644 include/CMakeLists.txt diff --git a/.gitignore b/.gitignore index d2b57124..414992b9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.creator.user* *.cflags *.cxxflags +*build* bin/*bc bin/*bc.exe bin/*dc @@ -78,6 +79,8 @@ core.* cscope*.out tags +.idea + *.vcxproj.user vs/.vs/* vs/bin/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 7422e3c9..0d625557 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.11) -project(bc VERSION 0.0.1 LANGUAGES C) +project(bc VERSION 6.6.0 LANGUAGES C) set(CMAKE_C_STANDARD 90) set(CMAKE_C_STANDARD_REQUIRED ON) @@ -11,14 +11,6 @@ if (NOT DEFINED MSVC_VERSION OR MSVC_VERSION STRGREATER "1900" # 2015 OR NOT (CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")) target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_${CMAKE_C_STANDARD}") -elseif ((MSVC_VERSION STRLESS_EQUAL "1900" - OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom" - OR CYGWIN) - AND NOT EXISTS "${CMAKE_BINARY_DIR}/c89stringutils_export.h") - file(COPY "${CMAKE_SOURCE_DIR}/c89stringutils/c89stringutils_export_pregen.h" - DESTINATION "${CMAKE_BINARY_DIR}") - file(RENAME "${CMAKE_BINARY_DIR}/c89stringutils_export_pregen.h" - "${CMAKE_BINARY_DIR}/c89stringutils_export.h") endif () if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15") # add compiler warning flags just when building this project via @@ -80,7 +72,6 @@ configure_file( # Doing this at the end so that all definitions and link/include paths are # available for the sub-projects. #=============================================================================== -add_subdirectory("include") add_subdirectory("src") ########### diff --git a/bcl.pc.in b/bcl.pc.in index f440eeca..f8edb5d0 100644 --- a/bcl.pc.in +++ b/bcl.pc.in @@ -2,7 +2,7 @@ includedir=%%INCLUDEDIR%% libdir=%%LIBDIR%% Name: bcl -Description: Implemention of arbitrary-precision math from the bc calculator. +Description: Implementation of arbitrary-precision math from the bc calculator. Version: %%VERSION%% Cflags: -I${includedir} Libs: -L${libdir} -lbcl diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt deleted file mode 100644 index 11420184..00000000 --- a/include/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -set(LIBRARY_NAME "${PROJECT_NAME}_includes") - -set(Header_Files - "args.h" - "bc.h" - "bcl.h" - "dc.h" - "file.h" - "history.h" - "lang.h" - "lex.h" - "library.h" - "num.h" - "opt.h" - "parse.h" - "program.h" - "rand.h" - "read.h" - "status.h" - "vector.h" - "version.h" - "vm.h" -) -source_group("Header Files" FILES "${Header_Files}") -add_library("${LIBRARY_NAME}" INTERFACE "${Header_Files}") - -include(GNUInstallDirs) -target_include_directories( - "${LIBRARY_NAME}" - INTERFACE - "$" - "$" - "$" -) - -target_link_libraries( - "${LIBRARY_NAME}" - INTERFACE - "${PROJECT_NAME}_compiler_flags" -) - -set_target_properties("${LIBRARY_NAME}" PROPERTIES LINKER_LANGUAGE C) - -install(FILES ${Header_Files} - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0adb326f..1eb3e848 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,10 +2,30 @@ # Library # ########### -include(CheckIncludeFile) - set(LIBRARY_NAME "${PROJECT_NAME}") +set(Header_Files + "../include/args.h" + "../include/bc.h" + "../include/bcl.h" + "../include/dc.h" + "../include/file.h" + "../include/history.h" + "../include/lang.h" + "../include/lex.h" + "../include/library.h" + "../include/num.h" + "../include/opt.h" + "../include/parse.h" + "../include/program.h" + "../include/rand.h" + "../include/status.h" + "../include/vector.h" + "../include/version.h" + "../include/vm.h" +) +source_group("Header Files" FILES "${Header_Files}") + set(Source_Files "args.c" "bc.c" @@ -32,7 +52,7 @@ set(Source_Files ) source_group("Source Files" FILES "${Source_Files}") -add_library("${LIBRARY_NAME}" "${Source_Files}") +add_library("${LIBRARY_NAME}" "${Header_Files}" "${Source_Files}") include(GNUInstallDirs) @@ -42,13 +62,15 @@ target_link_libraries( "${PROJECT_NAME}_compiler_flags" ) -target_link_libraries( +target_include_directories( "${LIBRARY_NAME}" PUBLIC - "${PROJECT_NAME}_includes" + "$" + "$" + "$" ) -#if (HAVE_BCRYPT) +# if (HAVE_BCRYPT) if (WIN32) target_link_libraries("${LIBRARY_NAME}" PUBLIC bcrypt.lib) endif () @@ -67,7 +89,7 @@ source_group("${EXEC_NAME} Source Files" FILES "${Cli_Source_Files}") add_executable("${EXEC_NAME}" "${Cli_Source_Files}") -target_link_libraries("${EXEC_NAME}" PUBLIC "${LIBRARY_NAME}") +target_link_libraries("${EXEC_NAME}" "${LIBRARY_NAME}") set_target_properties("${EXEC_NAME}" PROPERTIES LINKER_LANGUAGE C) @@ -81,8 +103,14 @@ include(GNUInstallDirs) set_property(TARGET "${LIBRARY_NAME}" PROPERTY VERSION "${${PROJECT_NAME}_VERSION}") set_property(TARGET "${LIBRARY_NAME}" PROPERTY SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}") +include(GenerateExportHeader) +set(_export_file "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}_export.h") +generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}") + +install(FILES ${Header_Files} "${_export_file}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + set(installable_libs - "${LIBRARY_NAME}_includes" "${LIBRARY_NAME}") if (TARGET "${DEPENDANT_LIBRARY}") list(APPEND installable_libs "${DEPENDANT_LIBRARY}") @@ -95,11 +123,5 @@ install(TARGETS ${installable_libs} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") -install(EXPORT "${LIBRARY_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}") - -include(GenerateExportHeader) -set(_export_file "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}_export.h") -generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}") - -install(FILES "${_export_file}" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install(EXPORT "${LIBRARY_NAME}Targets" + DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}") From b945314d5edcb660bc286f63e60a5a63697b9ee4 Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Fri, 18 Aug 2023 20:43:54 -0400 Subject: [PATCH 4/4] Improve CMake support --- include/bc.h | 15 ++++++++------- include/dc.h | 2 +- include/history.h | 8 ++++---- include/read.h | 2 +- include/vm.h | 12 ++++++++++-- src/CMakeLists.txt | 17 ++++++++++++----- src/vm.c | 2 +- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/include/bc.h b/include/bc.h index 0ce1da99..38855884 100644 --- a/include/bc.h +++ b/include/bc.h @@ -44,24 +44,25 @@ #include #include #include +#include "bc_export.h" /** * The main function for bc. It just sets variables and passes its arguments * through to @a bc_vm_boot(). */ -BC_EXPORT void +extern BCL_EXPORT void bc_main(int argc, char* argv[]); // These are references to the help text, the library text, and the "filename" // for the library. -extern const char bc_help[]; -extern BC_EXPORT const char bc_lib[]; -extern BC_EXPORT const char* bc_lib_name; +extern BCL_EXPORT const char bc_help[]; +extern BCL_EXPORT const char bc_lib[]; +extern BCL_EXPORT const char* bc_lib_name; // These are references to the second math library and its "filename." #if BC_ENABLE_EXTRA_MATH -extern BC_EXPORT const char bc_lib2[]; -extern BC_EXPORT const char* bc_lib2_name; +extern BCL_EXPORT const char bc_lib2[]; +extern BCL_EXPORT const char* bc_lib2_name; #endif // BC_ENABLE_EXTRA_MATH /** @@ -411,7 +412,7 @@ bc_parse_parse(BcParse* p); * function definition, we know we can add an empty else clause. * @param p The parser. */ -BC_EXPORT void +extern BCL_EXPORT void bc_parse_endif(BcParse* p); /// References to the signal message and its length. diff --git a/include/dc.h b/include/dc.h index 41afb6a5..12358e6d 100644 --- a/include/dc.h +++ b/include/dc.h @@ -46,7 +46,7 @@ * The main function for dc. It just sets variables and passes its arguments * through to @a bc_vm_boot(). */ -BC_EXPORT void +extern BCL_EXPORT void dc_main(int argc, char* argv[]); // A reference to the dc help text. diff --git a/include/history.h b/include/history.h index f01c9fcc..86757e13 100644 --- a/include/history.h +++ b/include/history.h @@ -342,7 +342,7 @@ typedef struct BcHistory * Frees strings used by history. * @param str The string to free. */ -BC_EXPORT void +extern BCL_EXPORT void bc_history_string_free(void* str); // A list of terminals that don't work. @@ -395,21 +395,21 @@ bc_history_printKeyCodes(BcHistory* h); * leave the terminal in raw mode or in some other half-baked * state. */ -BC_EXPORT BcStatus +extern BCL_EXPORT BcStatus bc_history_line(BcHistory* h, BcVec* vec, const char* prompt); /** * Initialize history data. * @param h The struct to initialize. */ -BC_EXPORT void +extern BCL_EXPORT void bc_history_init(BcHistory* h); /** * Free history data (and recook the terminal). * @param h The struct to free. */ -BC_EXPORT void +extern BCL_EXPORT void bc_history_free(BcHistory* h); #endif // BC_ENABLE_HISTORY diff --git a/include/read.h b/include/read.h index 50e34485..6e44995e 100644 --- a/include/read.h +++ b/include/read.h @@ -54,7 +54,7 @@ * @param vec The vector to put the stdin data into. * @param prompt The prompt to print, if desired. */ -BC_EXPORT BcStatus +extern BCL_EXPORT BcStatus bc_read_line(BcVec* vec, const char* prompt); /** diff --git a/include/vm.h b/include/vm.h index 86093ead..b6d17fab 100644 --- a/include/vm.h +++ b/include/vm.h @@ -146,6 +146,14 @@ /// The flag for the global stacks option. #define BC_FLAG_G (UINTMAX_C(1) << 4) +/** + * Loads a math library. + * @param name The name of the library. + * @param text The text of the source code. + */ +extern BCL_EXPORT void +bc_vm_load(const char* name, const char* text); + #endif // BC_ENABLED /// The flag for quiet, though this one is reversed; the option clears the flag. @@ -792,7 +800,7 @@ bc_vm_info(const char* const help); * @param argc The count of arguments. * @param argv The argument array. */ -BC_EXPORT void +extern BCL_EXPORT void bc_vm_boot(int argc, char* argv[]); /** @@ -805,7 +813,7 @@ bc_vm_init(void); /** * Frees the BcVm global. */ -BC_EXPORT void +extern BCL_EXPORT void bc_vm_shutdown(void); /** diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1eb3e848..0e1e20f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ # Library # ########### -set(LIBRARY_NAME "${PROJECT_NAME}") +set(LIBRARY_NAME "${PROJECT_NAME}l") set(Header_Files "../include/args.h" @@ -40,7 +40,6 @@ set(Source_Files "lang.c" "lex.c" "library.c" - "main.c" "num.c" "opt.c" "parse.c" @@ -75,6 +74,14 @@ if (WIN32) target_link_libraries("${LIBRARY_NAME}" PUBLIC bcrypt.lib) endif () +target_compile_definitions( + "${LIBRARY_NAME}" + PUBLIC + BC_ENABLE_EXTRA_MATH=1 + BC_ENABLE_HISTORY=1 + BC_ENABLED=1 +) + set_target_properties("${LIBRARY_NAME}" PROPERTIES LINKER_LANGUAGE C) @@ -82,7 +89,7 @@ set_target_properties("${LIBRARY_NAME}" PROPERTIES LINKER_LANGUAGE C) # CLI # ####### -set(EXEC_NAME "${PROJECT_NAME}_cli") +set(EXEC_NAME "${PROJECT_NAME}") set(Cli_Source_Files "main.c") source_group("${EXEC_NAME} Source Files" FILES "${Cli_Source_Files}") @@ -110,8 +117,8 @@ generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}") install(FILES ${Header_Files} "${_export_file}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") -set(installable_libs - "${LIBRARY_NAME}") +set(installable_libs # "${EXEC_NAME}" + "${LIBRARY_NAME}" ) if (TARGET "${DEPENDANT_LIBRARY}") list(APPEND installable_libs "${DEPENDANT_LIBRARY}") endif () diff --git a/src/vm.c b/src/vm.c index 41da0fd9..cb8f9e65 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1347,7 +1347,7 @@ bc_vm_exprs(void) * @param name The name of the library. * @param text The text of the source code. */ -static void +void bc_vm_load(const char* name, const char* text) { bc_lex_file(&vm->prs.l, name);