Skip to content

Commit

Permalink
Removed some outdated modules, and removed debug executable targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCG-coder committed Apr 7, 2024
1 parent c8f98fa commit 9fba390
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 516 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(STP_BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "The source directory of Steppable")

if (WIN32)
add_compile_definitions(WINDOWS)
if (MSVC) # MSVC Has no UTF-8 support by default
Expand Down Expand Up @@ -77,7 +79,6 @@ add_subdirectory(include/) # The CMakeLists file there adds the include/ directo
add_subdirectory(lib/)

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)


if (DEBUG)
Expand Down
4 changes: 2 additions & 2 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
#####################################################################################################

# Add include directory to all targets
foreach (TARGET IN LISTS TARGETS TEST_TARGETS)
target_include_directories(${TARGET} PUBLIC ./)
foreach (TARGET IN LISTS TEST_TARGETS)
target_include_directories(${TARGET} PUBLIC ${STP_BASE_DIRECTORY}/include/)
endforeach (TARGET)
57 changes: 44 additions & 13 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
set (Python_FIND_VIRTUALENV FIRST)
unset (Python_EXECUTABLE)
find_package (Python COMPONENTS Interpreter Development REQUIRED)
#####################################################################################################
# Copyright (c) 2023-2024 NWSOFT #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to deal #
# in the Software without restriction, including without limitation the rights #
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #
# copies of the Software, and to permit persons to whom the Software is #
# furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included in all #
# copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
# SOFTWARE. #
#####################################################################################################

# # Detect the installed nanobind package and import it into CMake
set(Python_FIND_VIRTUALENV ONLY)
unset(Python_EXECUTABLE)
find_package(
Python
COMPONENTS Development Development.SABIModule
REQUIRED)

# Detect the installed nanobind package and import it into CMake
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)
message(STATUS "Found nanobind: ${Python_EXECUTABLE}")
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE NB_DIR)
message(TRACE "Found nanobind: ${NB_DIR}")
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
find_package(nanobind CONFIG REQUIRED)

nanobind_add_module(bindings NB_STATIC LTO bindings.cpp)
target_link_options(bindings PRIVATE -Bsymbolic)
set_target_properties(bindings PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(bindings PRIVATE calc steppable)
target_compile_definitions(bindings PRIVATE NO_MAIN)
target_include_directories(bindings PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
# Python bindings for Steppable.
set(Python_INTERPRETER_ID ${Python3_INTERPRETER_ID} CACHE INTERNAL "Compatibility for nanobind")
nanobind_add_module(steppyble STABLE_ABI NB_STATIC LTO bindings.cpp)

if(NOT ${WINDOWS})
target_link_options(steppyble PRIVATE -Bsymbolic)
endif()
set_target_properties(steppyble PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(steppyble PRIVATE calc steppable)
target_compile_definitions(steppyble PRIVATE NO_MAIN)
target_include_directories(steppyble PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
24 changes: 23 additions & 1 deletion lib/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/**************************************************************************************************
* Copyright (c) 2023-2024 NWSOFT *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in all *
* copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
* SOFTWARE. *
**************************************************************************************************/

#include "fn/basicArithm.hpp"
#include "fraction.hpp"
#include "number.hpp"
Expand All @@ -12,7 +34,7 @@ namespace nb = nanobind;
using namespace steppable::__internals::arithmetic;
using namespace nb::literals;

NB_MODULE(bindings, mod)
NB_MODULE(steppyble, mod)
{
auto internals = mod.def_submodule("_internals", "Internal functions.");

Expand Down
52 changes: 25 additions & 27 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,37 @@

add_library(util STATIC argParse.cpp colors.cpp logging.cpp rounding.cpp symbols.cpp testing.cpp util.cpp)
set_target_properties(util PROPERTIES POSITION_INDEPENDENT_CODE ON)

add_library(steppable STATIC number.cpp fraction.cpp expression.cpp)
set_target_properties(steppable PROPERTIES POSITION_INDEPENDENT_CODE ON)
# file(GLOB GUIS gui/*.cpp)
# add_executable(gui ${GUIS})

set(CALCULATOR_FILES)

function(COPY_TO_BIN TARGET_NAME)
if (WINDOWS)
add_custom_command(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}>
${CMAKE_CURRENT_BINARY_DIR}/../bin/${TARGET_NAME}.exe)
else ()
add_custom_command(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}>
${CMAKE_CURRENT_BINARY_DIR}/../bin/${TARGET_NAME})
if (DEFINED STP_BUILD_COMPONENT_EXECUTABLE)
if (WINDOWS)
add_custom_command(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}>
${CMAKE_CURRENT_BINARY_DIR}/../bin/${TARGET_NAME}.exe)
else ()
add_custom_command(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}>
${CMAKE_CURRENT_BINARY_DIR}/../bin/${TARGET_NAME})
endif ()
endif ()
endfunction()

foreach (COMPONENT IN LISTS COMPONENTS)
message(STATUS "Adding component: ${COMPONENT}: ${COMPONENT}/${COMPONENT}.cpp, ${COMPONENT}/${COMPONENT}Report.cpp")
message(TRACE "Adding component: ${COMPONENT}: ${COMPONENT}/${COMPONENT}.cpp, ${COMPONENT}/${COMPONENT}Report.cpp")

# No longer offering executables for each component automatically.

add_executable(${COMPONENT} ${COMPONENT}/${COMPONENT}.cpp ${COMPONENT}/${COMPONENT}Report.cpp)
target_link_libraries(${COMPONENT} calc)
if (DEFINED STP_BUILD_COMPONENT_EXECUTABLE)
add_executable(${COMPONENT} ${COMPONENT}/${COMPONENT}.cpp ${COMPONENT}/${COMPONENT}Report.cpp)
target_link_libraries(${COMPONENT} calc)
endif ()

list(APPEND CALCULATOR_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/${COMPONENT}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/${COMPONENT}Report.cpp)
Expand All @@ -57,18 +62,11 @@ endforeach ()

add_library(calc STATIC ${CALCULATOR_FILES} fraction.cpp number.cpp expression.cpp)
set_target_properties(calc PROPERTIES POSITION_INDEPENDENT_CODE ON)

target_include_directories(steppable PRIVATE ${STP_BASE_DIRECTORY}/include/)
target_include_directories(calc PRIVATE ${STP_BASE_DIRECTORY}/include/)
target_include_directories(util PRIVATE ${STP_BASE_DIRECTORY}/include/)

target_link_libraries(steppable util)
target_link_libraries(calc steppable)
# target_link_libraries(gui util)
target_include_directories(calc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
# target_include_directories(gui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_compile_definitions(calc PRIVATE NO_MAIN)

add_executable(main main/main.cpp)
target_link_libraries(main calc)
target_include_directories(main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)

set(G_CALCULATOR_FILES ${CALCULATOR_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/fraction.cpp
${CMAKE_CURRENT_SOURCE_DIR}/number.cpp
${CMAKE_CURRENT_SOURCE_DIR}/expression.cpp
CACHE INTERNAL "Calculator files" FORCE)
Loading

0 comments on commit 9fba390

Please sign in to comment.