Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake support #68

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.creator.user*
*.cflags
*.cxxflags
*build*
bin/*bc
bin/*bc.exe
bin/*dc
Expand Down Expand Up @@ -78,6 +79,8 @@ core.*
cscope*.out
tags

.idea

*.vcxproj.user
vs/.vs/*
vs/bin/*
Expand Down
123 changes: 123 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
cmake_minimum_required(VERSION 3.11)

project(bc VERSION 6.6.0 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}")
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 "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
target_compile_options(
"${PROJECT_NAME}_compiler_flags"
INTERFACE
"$<${gcc_like}:$<BUILD_INTERFACE:-Wshadow;-Wformat=2;-Wall;-pedantic>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>"
)
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 "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
target_compile_options(
"${PROJECT_NAME}_compiler_flags"
INTERFACE
"$<${gcc_like}:$<BUILD_INTERFACE:-Wshadow;-Wformat=2;-Wall;-pedantic>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>"
)
endif ()

include(CheckSymbolExists)
check_symbol_exists(BCryptGenRandom "windows.h;bcrypt.h" HAVE_BCRYPT)

# 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"
)

#===============================================================================
# 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("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 "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")
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}")
2 changes: 1 addition & 1 deletion bcl.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file added cmake/BundleIcon.icns
Binary file not shown.
7 changes: 7 additions & 0 deletions cmake/CTestConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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")
set(CTEST_DROP_SITE_CDASH TRUE)
4 changes: 4 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

@PACKAGE_INIT@

include ( "${CMAKE_CURRENT_LIST_DIR}/bcTargets.cmake" )
Binary file added cmake/CustomVolumeIcon.icns
Binary file not shown.
14 changes: 14 additions & 0 deletions cmake/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>BundleGeneratorTest</string>
<key>CFBundleIconFile</key>
<string>BundleGeneratorTest.icns</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
6 changes: 6 additions & 0 deletions cmake/MultiCPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include("release/CPackConfig.cmake")

set(CPACK_INSTALL_CMAKE_PROJECTS
"debug;bc;ALL;/"
"release;bc;ALL;/"
)
5 changes: 5 additions & 0 deletions cmake/README.txt
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions cmake/Welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This installs bc.
11 changes: 11 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BC_CONFIG_H
#define BC_CONFIG_H

#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 */
15 changes: 8 additions & 7 deletions include/bc.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@
#include <status.h>
#include <lex.h>
#include <parse.h>
#include "bc_export.h"

/**
* The main function for bc. It just sets variables and passes its arguments
* through to @a bc_vm_boot().
*/
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 const char bc_lib[];
extern 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 const char bc_lib2[];
extern 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

/**
Expand Down Expand Up @@ -411,7 +412,7 @@ bc_parse_parse(BcParse* p);
* function definition, we know we can add an empty else clause.
* @param p The parser.
*/
void
extern BCL_EXPORT void
bc_parse_endif(BcParse* p);

/// References to the signal message and its length.
Expand Down
2 changes: 1 addition & 1 deletion include/dc.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* The main function for dc. It just sets variables and passes its arguments
* through to @a bc_vm_boot().
*/
void
extern BCL_EXPORT void
dc_main(int argc, char* argv[]);

// A reference to the dc help text.
Expand Down
10 changes: 6 additions & 4 deletions include/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <status.h>
Expand Down Expand Up @@ -340,7 +342,7 @@ typedef struct BcHistory
* Frees strings used by history.
* @param str The string to free.
*/
void
extern BCL_EXPORT void
bc_history_string_free(void* str);

// A list of terminals that don't work.
Expand Down Expand Up @@ -393,21 +395,21 @@ bc_history_printKeyCodes(BcHistory* h);
* leave the terminal in raw mode or in some other half-baked
* state.
*/
BcStatus
extern BCL_EXPORT BcStatus
bc_history_line(BcHistory* h, BcVec* vec, const char* prompt);

/**
* Initialize history data.
* @param h The struct to initialize.
*/
void
extern BCL_EXPORT void
bc_history_init(BcHistory* h);

/**
* Free history data (and recook the terminal).
* @param h The struct to free.
*/
void
extern BCL_EXPORT void
bc_history_free(BcHistory* h);

#endif // BC_ENABLE_HISTORY
Expand Down
3 changes: 2 additions & 1 deletion include/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include <status.h>
#include <vector.h>
#include "bc_export.h"

/**
* Returns true if @a c is a non-ASCII (invalid) char.
Expand All @@ -53,7 +54,7 @@
* @param vec The vector to put the stdin data into.
* @param prompt The prompt to print, if desired.
*/
BcStatus
extern BCL_EXPORT BcStatus
bc_read_line(BcVec* vec, const char* prompt);

/**
Expand Down
12 changes: 10 additions & 2 deletions include/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -792,7 +800,7 @@ bc_vm_info(const char* const help);
* @param argc The count of arguments.
* @param argv The argument array.
*/
void
extern BCL_EXPORT void
bc_vm_boot(int argc, char* argv[]);

/**
Expand All @@ -805,7 +813,7 @@ bc_vm_init(void);
/**
* Frees the BcVm global.
*/
void
extern BCL_EXPORT void
bc_vm_shutdown(void);

/**
Expand Down
Loading