Skip to content

Commit

Permalink
Much more proper-ish building with CMake on Linux. No more Jam!
Browse files Browse the repository at this point in the history
  • Loading branch information
chuma committed May 17, 2018
1 parent b766274 commit 121bc83
Show file tree
Hide file tree
Showing 18 changed files with 502 additions and 35 deletions.
143 changes: 143 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,143 @@
cmake_minimum_required(VERSION 3.11)

project(einstein)

set(INCLUDEPKGS TestBigEndian FindPkgConfig CheckLibraryExists)
foreach(pname IN LISTS INCLUDEPKGS)
include(${pname})
endforeach()

option(portaudio "PortAudio output support" OFF)
option(nativeportaudio "PortAudio (native library) support" OFF)
option(pulseaudio "PulseAudio output support" ON)
option(armlejit "Use ARMLE JIT" OFF)
option(appX11 "X11+CLI application" ON)
option(appFLTK "FLTK application" OFF)

set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})

# Release / Debug compile flags.
set(_FLAGS_DEBUG "-g -O0 -DDEBUG -DDEBUG_SOUND -DPA_ENABLE_DEBUG_OUTPUT -DHAS_C99_LONGLONG")
set(_FLAGS_RELEASE "-O3 -DRELEASE -DHAS_C99_LONGLONG")

set(CMAKE_CXX_FLAGS_RELEASE "${_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG "${_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_DEBUG "${_FLAGS_DEBUG}")

if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas -Wwrite-strings -Wno-multichar -Wfloat-equal -Wshadow -Wpointer-arith -Wconversion")
endif()

set(LINKLIBS)

find_library(M_LIB m)
list(APPEND LINKLIBS ${M_LIB})

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

set(CMAKE_THREAD_PREFER_PTHREAD)
find_package(Threads)
if (Threads_FOUND)
list(APPEND LINKLIBS pthread)
else()
message(FATAL_ERROR "Missing library: pthread")
endif()


find_library(FFI_LIB ffi)
find_library(DL_LIB dl)
list(APPEND LINKLIBS ${DL_LIB} ${PTHREAD_LIB} ${FFI_LIB})
endif()

TEST_BIG_ENDIAN(_IS_BIG_ENDIAN)
add_definitions(-DTARGET_RT_BIG_ENDIAN=$<BOOL:${_IS_BIG_ENDIAN}> -DTARGET_RT_LITTLE_ENDIAN=$<NOT:${_IS_BIG_ENDIAN}>)

# K Libs
add_subdirectory(K)

###########################
# Einstein library code

## 1) Gather all common sources

file(GLOB elib_common_sources "Emulator/*.cp")
file(GLOB elib_Monitor_sources "Monitor/*.cp")

set_source_files_properties(${elib_common_sources} PROPERTIES LANGUAGE CXX)
set_source_files_properties(${elib_Monitor_sources} PROPERTIES LANGUAGE CXX)

# Add "einsteinlib" as a library target
add_library(einsteinlib STATIC ${elib_common_sources} ${elib_Monitor_sources})

# add include directories ... do I need this?
target_include_directories(einsteinlib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:einsteinlib>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/Emulator
$<INSTALL_INTERFACE:einsteinlib>/Emulator
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/Emulator/JIT/Generic
$<INSTALL_INTERFACE:einsteinlib>/Emulator/JIT/Generic
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/Monitor/
$<INSTALL_INTERFACE:einsteinlib>/Monitor/
)

# Platform-specific stuff
if(${WIN32})
target_sources(einsteinlib PUBLIC "Emulator/Win32/CompatibilityWin32.cp")
set(EINSTEIN_TARGET "WIN32")
set(EINSTEIN_SCREEN_MANAGER "FL")

target_include_directories(einsteinlib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/Emulator/Win32
$<INSTALL_INTERFACE:einsteinlib>/Emulator/Win32
)
set_source_files_properties("Emulator/Win32/CompatibilityWin32.cp" PROPERTIES LANGUAGE CXX)
elseif(${UNIX})

if (${APPLE})
set(EINSTEIN_TARGET "MACOSX")
# FIXME add OS X sources here.
set(EINSTEIN_SCREEN_MANAGER "Cocoa")
else()
if (appX11)
set(EINSTEIN_SCREEN_MANAGER "X11")
endif()

if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "BSD")
set(EINSTEIN_TARGET "BSD")

else()
set(EINSTEIN_TARGET "LINUX")
endif()
endif()
endif()

add_definitions(-DTARGET_OS_${EINSTEIN_TARGET})

if (portaudio OR nativeportaudio)
add_definitions("-DAUDIO_PORTAUDIO=1")
endif()

if (pulseaudio)
add_definitions("-DAUDIO_PULSEAUDIO=1")
endif()

# Add the Emulator/ sub-dir, which has CMakeLists all the way down
add_subdirectory(Emulator)

string(TOUPPER ${CMAKE_HOST_SYSTEM_NAME} _LOCAL_LIB_DIR_SUFFIX)
install(TARGETS einsteinlib DESTINATION lib.${_LOCAL_LIB_DIR_SUFFIX})

target_link_libraries(einsteinlib files host jit log nativecalls network pcmcia platform rom screen serial sound ${LINKLIBS} k)


############################
# EINSTEIN EMULATOR
add_executable(einstein app/einstein.cp app/TCLIApp.cp)

install(TARGETS einstein DESTINATION einstein-${CMAKE_BUILD_TYPE})

set_source_files_properties(app/einstein.cp app/TCLIApp.cp PROPERTIES LANGUAGE CXX)
target_link_libraries(einstein k einsteinlib)
14 changes: 14 additions & 0 deletions Emulator/CMakeLists.txt
@@ -0,0 +1,14 @@
# Emulator CMakeLists.txt

add_subdirectory(Files)
add_subdirectory(Host)
add_subdirectory(JIT)
add_subdirectory(Log)
add_subdirectory(NativeCalls)
add_subdirectory(Network)
add_subdirectory(PCMCIA)
add_subdirectory(Platform)
add_subdirectory(ROM)
add_subdirectory(Screen)
add_subdirectory(Serial)
add_subdirectory(Sound)
16 changes: 16 additions & 0 deletions Emulator/Files/CMakeLists.txt
@@ -0,0 +1,16 @@
# Files CMakeLists.txt

file(GLOB headers *.h)
file(GLOB sources *.cp)

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(files STATIC ${sources})
target_include_directories(files PUBLIC
../
../JIT/
../JIT/Generic
../../
)

target_link_libraries(files k)
14 changes: 14 additions & 0 deletions Emulator/Host/CMakeLists.txt
@@ -0,0 +1,14 @@
# Host CMakeLists

file(GLOB headers *.h)
file(GLOB sources *.cp)

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(host STATIC ${sources})
target_include_directories(host PUBLIC
../
../../
)

target_link_libraries(host k)
58 changes: 58 additions & 0 deletions Emulator/JIT/CMakeLists.txt
@@ -0,0 +1,58 @@
# JIT CMakeLists.txt

set(elib_JIT_sources
"TJITCache.cp"
"TJITPage.cp"
"Generic/TJITGenericRetarget.cp"
"Generic/TJITGenericRetargetMap.cpp"
"Generic/TJITGenericROMPatch.cp"
"Generic/TJITGeneric_BlockDataTransfer.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer_MRS.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer_ArithmeticOp.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer_LogicalOp.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer_MRS.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer_MSR.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer_MoveOp.cp"
"Generic/TJITGeneric_DataProcessingPSRTransfer_TestOp.cp"
"Generic/TJITGeneric_Multiply.cp"
"Generic/TJITGeneric_MultiplyAndAccumulate.cp"
"Generic/TJITGeneric_Other.cp"
"Generic/TJITGeneric_SingleDataSwap.cp"
"Generic/TJITGeneric_SingleDataTransfer.cp"
"Generic/TJITGeneric_Other.cp"
"Generic/TJITGeneric_Test.cp"
)

set(elib_jit_generic_sources
"Generic/TJITGeneric.cp"
"Generic/TJITGenericPage.cp"
)

set(elib_jit_armle_sources
"ARMLE/TJITARMLE.cp"
"ARMLE/TJITARMLEPage.cp"
"ARMLE/JITARMLEGlue.s"
)

if(armlejit)
set(elib_JIT_sources ${elib_JIT_sources} ${elib_jit_armle_sources})
else()
set(elib_JIT_sources ${elib_JIT_sources} ${elib_jit_generic_sources})
endif()

set_source_files_properties(${elib_JIT_sources} PROPERTIES LANGUAGE CXX)

add_library(jit STATIC ${elib_JIT_sources})

target_include_directories(jit PUBLIC
Generic/
../
../JIT
../JIT/Generic
../ROM
../../
../../Monitor
)

target_link_libraries(jit k)
14 changes: 14 additions & 0 deletions Emulator/Log/CMakeLists.txt
@@ -0,0 +1,14 @@
# Log CMakeLists

file(GLOB headers *.h)
file(GLOB sources *.cp)

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(log STATIC ${sources})
target_include_directories(log PUBLIC
../
../../
)

target_link_libraries(log k)
16 changes: 16 additions & 0 deletions Emulator/NativeCalls/CMakeLists.txt
@@ -0,0 +1,16 @@
# NativeCalls CMakeLists

file(GLOB headers *.h)
file(GLOB sources *.cp)

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(nativecalls STATIC ${sources})
target_include_directories(nativecalls PUBLIC
../
../JIT/
../JIT/Generic/
../../
)

target_link_libraries(nativecalls k)
19 changes: 19 additions & 0 deletions Emulator/Network/CMakeLists.txt
@@ -0,0 +1,19 @@
# Network CMakeLists.txt

# Only this one compiles for now ...
set(sources TNetworkManager.cp TUsermodeNetwork.cp)

# TODO virtual serial port

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(network STATIC ${sources})

target_include_directories(network PUBLIC
../
../JIT/
../JIT/Generic
../../
)

target_link_libraries(network k)
16 changes: 16 additions & 0 deletions Emulator/PCMCIA/CMakeLists.txt
@@ -0,0 +1,16 @@
# CMakeLists.txt

file(GLOB headers *.h)
file(GLOB sources *.cp)

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(pcmcia STATIC ${sources})
target_include_directories(pcmcia PUBLIC
../
../JIT/
../JIT/Generic
../../
)

target_link_libraries(pcmcia k)
16 changes: 16 additions & 0 deletions Emulator/Platform/CMakeLists.txt
@@ -0,0 +1,16 @@
# Platform CMakeLists

file(GLOB headers *.h)
file(GLOB sources *.cp)

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(platform STATIC ${sources})
target_include_directories(platform PUBLIC
../
../JIT/
../JIT/Generic
../../
)

target_link_libraries(platform host pcmcia k)
17 changes: 17 additions & 0 deletions Emulator/ROM/CMakeLists.txt
@@ -0,0 +1,17 @@
# ROM CMakeLists

file(GLOB headers *.h)
file(GLOB sources *.cp)

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(rom STATIC ${sources})
target_include_directories(rom PUBLIC
../
../JIT/
../JIT/Generic/
../Screen/
../../
)

target_link_libraries(rom k)
38 changes: 38 additions & 0 deletions Emulator/Screen/CMakeLists.txt
@@ -0,0 +1,38 @@
# Screen CMakeLists.txt

file(GLOB headers *.h)

set(sources TScreenManager.cp TNullScreenManager.cp)

if(EINSTEIN_SCREEN_MANAGER STREQUAL "X11")
find_package(X11)

if (X11_FOUND)
list(APPEND LINKLIBS ${X11_LIBRARIES})
else()
message(FATAL_ERROR "Missing library: X11")
endif()
elseif(EINSTEIN_SCREEN_MANAGER STREQUAL "FL")
find_package(FLTK)

if (FLTK_FOUND)
list(APPEND LINKLIBS FLTK_LIBRARIES)
else()
message(FATAL_ERROR "Missing library: fltk")
endif()
endif()

set(sources ${sources} "T${EINSTEIN_SCREEN_MANAGER}ScreenManager.cp")

set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)

add_library(screen STATIC ${sources})

target_include_directories(screen PUBLIC
../
../JIT/
../JIT/Generic/
../../
)

target_link_libraries(screen ${LINKLIBS} k)

0 comments on commit 121bc83

Please sign in to comment.