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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions BEESRC/BTL_PRF/CDE/C/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_library(BTL_PRF OBJECT
btl_prf_ffnc_ctx.c
btl_prf_ffnc_obj.c
prf_seq_stp_ffnc_ctx.c
prf_seq_stp_ffnc_obj.c
btl_proof_seq_ctx.c
btl_proof_seq_obj.c
btl_proof_str_ctx.c
btl_proof_str_obj.c
btl_proof_file_dump.c
btl_proof.c
btl_proofCtx.c
)
target_compile_definitions(BTL_PRF PUBLIC bmotif)
target_compile_options(BTL_PRF PUBLIC ${ALLOW_COMMON_FLAG})
118 changes: 118 additions & 0 deletions BEESRC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# Disambiguate files by creating separate include directories
set(B_CORE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.B-Core)
set(BMOTIF_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.motif)
set(BPLATFORM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.bplatform)

add_subdirectory(BTL_PRF/CDE/C)

# Copy files during configuration step
configure_file(itfmch.c.B-Core ${B_CORE_INCLUDE_DIR}/itfmch.c COPYONLY)
configure_file(natmch.c.B-Core ${B_CORE_INCLUDE_DIR}/natmch.c COPYONLY)
configure_file(filmch.c.B-Core ${B_CORE_INCLUDE_DIR}/filmch.c COPYONLY)
configure_file(themch.c.B-Core ${B_CORE_INCLUDE_DIR}/themch.c COPYONLY)
configure_file(prfmch.c.B-Core ${B_CORE_INCLUDE_DIR}/prfmch.c COPYONLY)
configure_file(tolmch.c.B-Core ${B_CORE_INCLUDE_DIR}/tolmch.c COPYONLY)
configure_file(symmch.c.B-Core ${B_CORE_INCLUDE_DIR}/symmch.c COPYONLY)
configure_file(strmch.c.B-Core ${B_CORE_INCLUDE_DIR}/strmch.c COPYONLY)
configure_file(lexmch.c.B-Core ${B_CORE_INCLUDE_DIR}/lexmch.c COPYONLY)
configure_file(frmmch.c.B-Core ${B_CORE_INCLUDE_DIR}/frmmch.c COPYONLY)
configure_file(errmch.c.B-Core ${B_CORE_INCLUDE_DIR}/errmch.c COPYONLY)
configure_file(macmch.c.B-Core ${B_CORE_INCLUDE_DIR}/macmch.c COPYONLY)
configure_file(rulmch.c.B-Core ${B_CORE_INCLUDE_DIR}/rulmch.c COPYONLY)
configure_file(resmch.c.B-Core ${B_CORE_INCLUDE_DIR}/resmch.c COPYONLY)
configure_file(hypmch.c.B-Core ${B_CORE_INCLUDE_DIR}/hypmch.c COPYONLY)
configure_file(tacmch.c.B-Core ${B_CORE_INCLUDE_DIR}/tacmch.c COPYONLY)
configure_file(nodmch.c.B-Core ${B_CORE_INCLUDE_DIR}/nodmch.c COPYONLY)
configure_file(golmch.c.B-Core ${B_CORE_INCLUDE_DIR}/golmch.c COPYONLY)
configure_file(seqmch.c.B-Core ${B_CORE_INCLUDE_DIR}/seqmch.c COPYONLY)

add_executable(b
b.c
)

target_include_directories(b PRIVATE ${B_CORE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

# Copy files for BTool build
configure_file(itfmch.c.motif ${BMOTIF_INCLUDE_DIR}/itfmch.c COPYONLY)
configure_file(natmch.c.motif ${BMOTIF_INCLUDE_DIR}/natmch.c COPYONLY)
configure_file(filmch.c.motif ${BMOTIF_INCLUDE_DIR}/filmch.c COPYONLY)
configure_file(themch.c.motif ${BMOTIF_INCLUDE_DIR}/themch.c COPYONLY)
configure_file(prfmch.c.motif ${BMOTIF_INCLUDE_DIR}/prfmch.c COPYONLY)
configure_file(tolmch.c.motif ${BMOTIF_INCLUDE_DIR}/tolmch.c COPYONLY)
configure_file(symmch.c.motif ${BMOTIF_INCLUDE_DIR}/symmch.c COPYONLY)
configure_file(strmch.c.motif ${BMOTIF_INCLUDE_DIR}/strmch.c COPYONLY)
configure_file(lexmch.c.motif ${BMOTIF_INCLUDE_DIR}/lexmch.c COPYONLY)
configure_file(frmmch.c.motif ${BMOTIF_INCLUDE_DIR}/frmmch.c COPYONLY)
configure_file(errmch.c.motif ${BMOTIF_INCLUDE_DIR}/errmch.c COPYONLY)
configure_file(macmch.c.motif ${BMOTIF_INCLUDE_DIR}/macmch.c COPYONLY)
configure_file(rulmch.c.motif ${BMOTIF_INCLUDE_DIR}/rulmch.c COPYONLY)
configure_file(resmch.c.motif ${BMOTIF_INCLUDE_DIR}/resmch.c COPYONLY)
configure_file(hypmch.c.motif ${BMOTIF_INCLUDE_DIR}/hypmch.c COPYONLY)
configure_file(tacmch.c.motif ${BMOTIF_INCLUDE_DIR}/tacmch.c COPYONLY)
configure_file(nodmch.c.motif ${BMOTIF_INCLUDE_DIR}/nodmch.c COPYONLY)
configure_file(golmch.c.motif ${BMOTIF_INCLUDE_DIR}/golmch.c COPYONLY)
configure_file(seqmch.c.motif ${BMOTIF_INCLUDE_DIR}/seqmch.c COPYONLY)

find_package(X11 REQUIRED)
find_package(Motif REQUIRED)
if (NOT X11_Xt_FOUND)
message(FATAL_ERROR "X Toolkit is required")
endif()

add_executable(BTool
bmotif.c
)

target_compile_definitions(BTool PUBLIC BTOOL_FLAG BTOOLM_FLAG)
target_include_directories(BTool PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${MOTIF_INCLUDE_DIR})
target_link_libraries(BTool PUBLIC BToolkitlm_globals ${MOTIF_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB} ${CUSERID_LIB})

# Copy symbol file
configure_file(SYMBOL ${BPLATFORM_BINARY_DIR}/SYMBOL COPYONLY)

# Copy files for bplatform build (note the suffix is actually 'release')
configure_file(itfmch.c.release ${BPLATFORM_INCLUDE_DIR}/itfmch.c COPYONLY)
configure_file(natmch.c.release ${BPLATFORM_INCLUDE_DIR}/natmch.c COPYONLY)
configure_file(filmch.c.release ${BPLATFORM_INCLUDE_DIR}/filmch.c COPYONLY)
configure_file(themch.c.release ${BPLATFORM_INCLUDE_DIR}/themch.c COPYONLY)
configure_file(prfmch.c.release ${BPLATFORM_INCLUDE_DIR}/prfmch.c COPYONLY)
configure_file(tolmch.c.release ${BPLATFORM_INCLUDE_DIR}/tolmch.c COPYONLY)
configure_file(symmch.c.release ${BPLATFORM_INCLUDE_DIR}/symmch.c COPYONLY)
configure_file(strmch.c.release ${BPLATFORM_INCLUDE_DIR}/strmch.c COPYONLY)
configure_file(lexmch.c.release ${BPLATFORM_INCLUDE_DIR}/lexmch.c COPYONLY)
configure_file(frmmch.c.release ${BPLATFORM_INCLUDE_DIR}/frmmch.c COPYONLY)
configure_file(errmch.c.release ${BPLATFORM_INCLUDE_DIR}/errmch.c COPYONLY)
configure_file(macmch.c.release ${BPLATFORM_INCLUDE_DIR}/macmch.c COPYONLY)
configure_file(rulmch.c.release ${BPLATFORM_INCLUDE_DIR}/rulmch.c COPYONLY)
configure_file(resmch.c.release ${BPLATFORM_INCLUDE_DIR}/resmch.c COPYONLY)
configure_file(hypmch.c.release ${BPLATFORM_INCLUDE_DIR}/hypmch.c COPYONLY)
configure_file(tacmch.c.release ${BPLATFORM_INCLUDE_DIR}/tacmch.c COPYONLY)
configure_file(nodmch.c.release ${BPLATFORM_INCLUDE_DIR}/nodmch.c COPYONLY)
configure_file(golmch.c.release ${BPLATFORM_INCLUDE_DIR}/golmch.c COPYONLY)
configure_file(seqmch.c.release ${BPLATFORM_INCLUDE_DIR}/seqmch.c COPYONLY)

add_executable(bplatform
bplatform.c
)
target_include_directories(bplatform PUBLIC ${BPLATFORM_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(bplatform PUBLIC bplatform)
set_target_properties(bplatform PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${BPLATFORM_BINARY_DIR}
)

add_library(BM OBJECT
appmch.motif.c
motif.c
bmotif_sub.c
bmotif.c
)
target_compile_definitions(BM PUBLIC
bmotif
BTOOLKIT_FLAG
BTOOL_FLAG
BTOOLM_FLAG
)
target_include_directories(BM PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${MOTIF_INCLUDE_DIR})
target_compile_options(BM PUBLIC ${ALLOW_COMMON_FLAG})
81 changes: 81 additions & 0 deletions C/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BLIB_BINARY_DIR})

add_executable(BProcessInfo
BProcessInfo.c
)

add_executable(BToolkit
BToolkit.c
)

add_executable(BUnlock
BUnlock.c
)

add_executable(BSession
BSession.c
)

add_executable(CheckRenameLib
CheckRenameLib.c
)

add_executable(CreHtml
CreHtml.c
)

add_executable(CreHtmlc
CreHtmlc.c
)

add_executable(Greplace
Greplace.c
)

add_executable(LatexProofFilter
LatexProofFilter.c
)

add_executable(CheckAnnot
Proof.c
)

add_executable(WaitX
WaitX.c
)

add_executable(Unix2Dos
Unix2Dos.c
)

add_executable(Dos2Unix
Dos2Unix.c
)

add_library(BToolkitlm_globals OBJECT
BToolkitlm_globals.c
)
target_compile_definitions(BToolkitlm_globals PUBLIC
BTOOL_FLAG
BTOOLM_FLAG
)

if (BUILD_CUSERID)
add_library(cuserid OBJECT
cuserid.c
)
endif()

find_package(Motif REQUIRED)

add_library(ClientSocket OBJECT
ClientSocket.c
)
target_compile_definitions(ClientSocket PUBLIC
bmotif
BTOOLKIT_FLAG
BTOOL_FLAG
BTOOLM_FLAG
)
target_include_directories(ClientSocket PUBLIC ${MOTIF_INCLUDE_DIR})
target_compile_options(ClientSocket PUBLIC ${ALLOW_COMMON_FLAG})
73 changes: 73 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
cmake_minimum_required(VERSION 3.11)

project(BToolkit
VERSION 6.0.4
DESCRIPTION "The BToolkit, a toolkit supporting software development with the B-method."
LANGUAGES C
)

# FIXME scripts set this unconditionally, may warrant some investigation
set(WITH_BSERVER ON CACHE BOOL "Build with BSERVER support" FORCE)

# Test compiler flags
include(CheckCCompilerFlag)

# TODO better flag dispatch?
# - Function/loop for repeated check and set?
# - Scripts set optimization levels differently for different files, is that
# needed with modern compilers (and especially with -pedantic)?

CHECK_C_COMPILER_FLAG(-pedantic USE_PEDANTIC)
if(USE_PEDANTIC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
endif()

CHECK_C_COMPILER_FLAG(-pipe USE_PIPE)
if(USE_PIPE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe")
endif()

CHECK_C_COMPILER_FLAG(-fcommon USE_FCOMMON)
if(USE_FCOMMON)
set(ALLOW_COMMON_FLAG -fcommon)
endif()

add_compile_definitions(RELEASE_VERSION)

if(WITH_BSERVER)
add_compile_definitions(BSERVER_VERSION)
endif()

# FIXME the scripts define a number of architectures, likely a lot of those
# would be hard to find and may not have a CMake port. Platform detection
# section attempts to deal with that one OS at a time, rather than porting all
# settings over to CMake

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(BUILD_CUSERID OFF)
add_compile_definitions(linux _BSD_SOURCE POSIX_SOURCE LINUX_VERSION LINUX_SUB_VERSION)
else()
set(BUILD_CUSERID ON)
add_compile_definitions(UNKNOWN_VERSION UNKNOWN_SUB_VERSION)
endif()

# Resolve what should be on link line for cuserid()
set(CUSERID_TARGET cuserid)
if (BUILD_CUSERID)
set(CUSERID_LIB ${CUSERID_TARGET})
else()
set(CUSERID_LIB ${CUSERID_SYS_LIB})
endif()

# Binary directories
set(BPLATFORM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/BPLAT)
set(BLIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/BLIB)

add_subdirectory(C)
add_subdirectory(BEESRC)
add_subdirectory(SRC)
add_subdirectory(LEX)
add_subdirectory(MOTIF)
add_subdirectory(SCRIPTS)
add_subdirectory(LIB)

44 changes: 44 additions & 0 deletions LEX/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
find_package(FLEX REQUIRED)
# TODO scripts try to increase input buffer sizes, but currently those
# variables are not found in the output

# There is a number of identically built utilities
set(FLEX_UTILS
AFilter
DFilter
Deannot
Doc_Latexer
EFilter
IFilter
Latex_Index
NLFilter
Post_Latexer_0
Pre_GML_0
Pre_GML_1
Pre_GML_2
Pre_GML_3
Pre_GML_4
Pre_GML_5
SFilter
TransCFilter
Html1
Html2
Html3
Html4
Html5
)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BLIB_BINARY_DIR})

# Repeat the same build steps
foreach(U IN LISTS FLEX_UTILS)
FLEX_TARGET(${U}C ${U}.lex ${CMAKE_CURRENT_BINARY_DIR}/${U}.c
COMPILE_FLAGS -n
)

add_executable(${U}
${FLEX_${U}C_OUTPUTS}
)
target_link_libraries(${U} PUBLIC ${FLEX_LIBRARIES})
endforeach()

Loading