configure gcc to pass the right linker flags & simplify CMakeLists

It is no longer necessary to pass special compiler options in order to compile an application.
This commit is contained in:
Wolfgang Thaller 2014-09-30 11:21:08 +02:00
parent 4e766452b4
commit 3f2a63ff40
9 changed files with 89 additions and 101 deletions

View File

@ -18,8 +18,50 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
project(Retro) project(Retro)
include(CMakeParseArguments)
function(add_application name)
set(options DEBUGBREAK CONSOLE)
set(oneValueArgs TYPE CREATOR)
set(multiValueArgs FILES MAKEAPPL_ARGS)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
list(APPEND ARGS_FILES ${ARGS_UNPARSED_ARGUMENTS})
set(files)
foreach(f ${ARGS_FILES})
list(APPEND files "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
endforeach()
add_executable(${name} ${files})
if(${ARGS_DEBUGBREAK})
list(APPEND ARGS_MAKEAPPL_ARGS -b)
endif()
if(${ARGS_CONSOLE})
target_link_libraries(${name} RetroConsole)
endif()
if(TARGET libretro)
set_target_properties(${name} PROPERTIES LINK_DEPENDS libretro)
endif(TARGET libretro)
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}.flt)
add_custom_command(
OUTPUT ${name}.bin ${name} ${name}.dsk
COMMAND ${MAKE_APPL} ${ARGS_MAKEAPPL_ARGS} -c "${name}.flt" -o "${name}"
DEPENDS ${name})
add_custom_target(${name}_APPL ALL DEPENDS ${name}.bin)
endfunction()
if(CMAKE_SYSTEM_NAME MATCHES Retro68) if(CMAKE_SYSTEM_NAME MATCHES Retro68)
add_subdirectory(libretro) add_subdirectory(libretro)
# add library path so that GCC picks up the freshly-built libretro
link_directories(${CMAKE_CURRENT_BINARY_DIR}/libretro)
add_subdirectory(Console) add_subdirectory(Console)
add_subdirectory(TestApps) add_subdirectory(TestApps)
add_subdirectory(Raytracer) add_subdirectory(Raytracer)

View File

@ -25,13 +25,10 @@ add_library(RetroConsole
InitConsole.cc InitConsole.cc
) )
add_executable(HelloWorld install(TARGETS RetroConsole DESTINATION lib)
add_application(HelloWorld
hello.c hello.c
CONSOLE
) )
target_link_libraries(HelloWorld RetroConsole retrocrt)
add_custom_command(
OUTPUT HelloWorld.bin
COMMAND ${MAKE_APPL} -c HelloWorld -o HelloWorld
DEPENDS HelloWorld)
add_custom_target(HelloWorldAPPL ALL DEPENDS HelloWorld.bin)

View File

@ -1,11 +1,6 @@
set(CMAKE_C_FLAGS "-Wno-multichar") cmake_minimum_required(VERSION 2.8)
add_executable(Launcher
Launcher.c
)
target_link_libraries(Launcher RetroConsole retrocrt) set(CMAKE_C_FLAGS "-Wno-multichar")
add_custom_command(
OUTPUT Launcher.bin add_application(Launcher
COMMAND ${MAKE_APPL} -c Launcher -o Launcher FILES Launcher.c CONSOLE)
DEPENDS Launcher)
add_custom_target(LauncherAPPL ALL DEPENDS Launcher.bin)

View File

@ -17,11 +17,7 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
if(NOT APPLE) if(APPLE)
set(CMAKE_CXX_FLAGS "-std=c++11 -fno-threadsafe-statics -g -fomit-frame-pointer") # -mcpu=68040")
endif()
include_directories(../App2)
add_executable(Raytracer MACOSX_BUNDLE add_executable(Raytracer MACOSX_BUNDLE
raytracer.c raytracer.c
) )
@ -31,31 +27,23 @@ add_executable(Raytracer2 MACOSX_BUNDLE
fixed.cc fixed.cc
) )
if(APPLE)
target_link_libraries(Raytracer "-framework Carbon") target_link_libraries(Raytracer "-framework Carbon")
target_link_libraries(Raytracer2 "-framework Carbon") target_link_libraries(Raytracer2 "-framework Carbon")
else() else()
add_executable(FixedBenchmark fixedbenchmark.cc fixed.h fixed.cc) set(CMAKE_CXX_FLAGS "-std=c++11")
target_link_libraries(FixedBenchmark RetroConsole retrocrt)
add_custom_command(
OUTPUT FixedBenchmark.bin
COMMAND ${MAKE_APPL} -c FixedBenchmark -o FixedBenchmark
DEPENDS FixedBenchmark)
add_custom_target(FixedBenchmarkAPPL ALL DEPENDS FixedBenchmark.bin)
target_link_libraries(Raytracer retrocrt) add_application(Raytracer
add_custom_command( raytracer.c
OUTPUT Raytracer.bin )
COMMAND ${MAKE_APPL} -c Raytracer -o Raytracer
DEPENDS Raytracer)
target_link_libraries(Raytracer "-lm") target_link_libraries(Raytracer "-lm")
add_custom_target(RaytracerAPPL ALL DEPENDS Raytracer.bin)
target_link_libraries(Raytracer2 retrocrt) add_application(Raytracer2
add_custom_command( raytracer2.cc
OUTPUT Raytracer2.bin fixed.h
COMMAND ${MAKE_APPL} -c Raytracer2 -o Raytracer2 fixed.cc
DEPENDS Raytracer2) )
add_custom_target(Raytracer2APPL ALL DEPENDS Raytracer2.bin)
add_application(FixedBenchmark CONSOLE
FILES fixedbenchmark.cc fixed.h fixed.cc)
endif() endif()

View File

@ -18,43 +18,13 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "-std=c++11") # -fomit-frame-pointer") set(CMAKE_CXX_FLAGS "-std=c++11") # -fomit-frame-pointer")
add_executable(ExceptionTest add_application(ExceptionTest CONSOLE ExceptionTest.cc)
ExceptionTest.cc add_application(InitTest CONSOLE InitTest.cc)
)
target_link_libraries(ExceptionTest RetroConsole retrocrt)
add_custom_command(
OUTPUT ExceptionTest.bin
COMMAND ${MAKE_APPL} -c ExceptionTest -o ExceptionTest
DEPENDS ExceptionTest)
add_custom_target(ExceptionTestAPPL ALL DEPENDS ExceptionTest.bin)
add_executable(InitTest
InitTest.cc
)
target_link_libraries(InitTest RetroConsole retrocrt)
add_custom_command(
OUTPUT InitTest.bin
COMMAND ${MAKE_APPL} -b -c InitTest -o InitTest
DEPENDS InitTest)
add_custom_target(InitTestAPPL ALL DEPENDS InitTest.bin)
enable_language(ASM) enable_language(ASM)
add_executable(AsmTest add_application(AsmTest AsmTest.s)
AsmTest.s
)
set_target_properties(AsmTest PROPERTIES LINKER_LANGUAGE C) set_target_properties(AsmTest PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(AsmTest retrocrt)
add_custom_command(
OUTPUT AsmTest.bin
COMMAND ${MAKE_APPL} -c AsmTest -o AsmTest
DEPENDS AsmTest)
add_custom_target(AsmTestAPPL ALL DEPENDS AsmTest.bin)
set(UPLOAD_URL "" CACHE STRING "ftp url to upload to") set(UPLOAD_URL "" CACHE STRING "ftp url to upload to")
if(UPLOAD_URL) if(UPLOAD_URL)

View File

@ -53,6 +53,9 @@ along with GCC; see the file COPYING3. If not see
#define SUBTARGET_EXTRA_SPECS #define SUBTARGET_EXTRA_SPECS
#define LIBGCC_SPEC "-lretrocrt -lgcc"
#define LINK_SPEC "-elf2flt -q -undefined=_consolewrite"
/* Note that some other tm.h files include this one and then override /* Note that some other tm.h files include this one and then override
many of the definitions that relate to assembler syntax. */ many of the definitions that relate to assembler syntax. */

View File

@ -651,7 +651,7 @@ case "${host}" in
newlib_cflags="${newlib_cflags} -DNO_EXEC -DABORT_PROVIDED -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES" newlib_cflags="${newlib_cflags} -DNO_EXEC -DABORT_PROVIDED -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
;; ;;
m68k-unknown-elf) m68k-unknown-elf)
newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES" newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES -DMALLOC_PROVIDED"
syscall_dir= syscall_dir=
;; ;;
mcore-*-*) mcore-*-*)

View File

@ -16,17 +16,12 @@
# along with Retro68. If not, see <http://www.gnu.org/licenses/>. # along with Retro68. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
add_library(retrocrt_multi
start.c add_library(retrocrt start.c
malloc.c malloc.c
syscalls.c syscalls.c
) glue.c
add_custom_command( consolehooks.c)
OUTPUT retrocrt.o
DEPENDS retrocrt_multi
COMMAND ${CMAKE_LINKER} -r -o retrocrt.o
--whole-archive libretrocrt_multi.a
)
add_library(retrocrt retrocrt.o glue.c consolehooks.c)
#add_custom_target(retrocrt_o ALL DEPENDS retrocrt.o)
install(TARGETS retrocrt DESTINATION lib) install(TARGETS retrocrt DESTINATION lib)

View File

@ -26,5 +26,3 @@ set( MAKE_APPL "${RETRO68_ROOT}/bin/MakeAPPL" )
set( CMAKE_C_COMPILER "${RETRO68_ROOT}/bin/m68k-unknown-elf-gcc" ) set( CMAKE_C_COMPILER "${RETRO68_ROOT}/bin/m68k-unknown-elf-gcc" )
set( CMAKE_CXX_COMPILER "${RETRO68_ROOT}/bin/m68k-unknown-elf-g++" ) set( CMAKE_CXX_COMPILER "${RETRO68_ROOT}/bin/m68k-unknown-elf-g++" )
set( CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-elf2flt -Wl,-q -Wl,-Map=linkmap.txt -Wl,-undefined=consolewrite" )