CMakeLists.txt 23.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW) # link to full path of libs
    cmake_policy(SET CMP0005 NEW) # escapes in add_definitions
endif()

option(ENABLE_VCPKG "Use dependencies for Visual Studio from vcpkg" ON)

set(NLS_DEFAULT ON)

# get win32 deps before project declaration, because toolchain is set for vcpkg
set(VCPKG_DEPS zlib libpng SDL2 SFML gettext wxWidgets)

include(${CMAKE_SOURCE_DIR}/cmake/Win32Deps.cmake)

15
project(VBA-M C CXX)
shuffle2's avatar
shuffle2 committed
16

17
cmake_minimum_required(VERSION 2.8.12)
18

19
20
21
22
23
24
25
if(NOT CMAKE_PREFIX_PATH AND (NOT ("$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")))
    set(CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "")
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build Type" FORCE)
endif()
26

27
set(ALL_TARGETS fex visualboyadvance-m vbamcore vbam)
28

29
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
30
#Output all binaries at top level
31
32
33
34
35
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})

option(ENABLE_SDL "Build the SDL port" OFF)
option(ENABLE_WX "Build the wxWidgets port" ON)
option(ENABLE_DEBUGGER "Enable the debugger" ON)
36
option(ENABLE_ASAN "Enable -fsanitize=<option>, address by default, requires debug build" OFF)
37
38
39
40
41
42
43
44
45
46
47

option(VBAM_STATIC "Try to link all libraries statically" OFF)

if(VBAM_STATIC)
    set(SDL2_STATIC ON)
    set(SFML_STATIC_LIBRARIES ON)
    set(FFMPEG_STATIC ON)
    set(SSP_STATIC ON)
    set(OPENAL_STATIC ON)
endif()

48
49
50
51
52
53
54
55
56
set(ENABLE_BUNDLED_LIBS_DEFAULT OFF)

# on visual studio use all bundled stuff
if(MSVC)
    set(ENABLE_BUNDLED_LIBS_DEFAULT ON)
endif()

# XXX: do some stuff with this
#option(ENABLE_BUNDLED_LIBS "Use bundled libraries instead of system libraries" ${ENABLE_BUNDLED_LIBS_DEFAULT})
57

58
# use ccache if available, and not already enabled on the command line
59
60
61
62
63
64
65
66
67
# but not with ninja and msys ccache on msys2
if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL "") AND CMAKE_GENERATOR STREQUAL Ninja))
    if(NOT CMAKE_CXX_COMPILER_LAUNCHER AND NOT CMAKE_C_COMPILER_LAUNCHER)
        find_program(CCACHE_FOUND ccache)
        if(CCACHE_FOUND)
            set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
            set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
        endif(CCACHE_FOUND)
    endif()
68
endif()
Rafael Kitover's avatar
Rafael Kitover committed
69

70
71
72
73
set(SSP_DEFAULT OFF)

option(ENABLE_SSP "Enable gcc stack protector support" ${SSP_DEFAULT})

74
75
76
77
set(ASM_DEFAULT OFF)

include(Architecture)

78
option(ENABLE_ASM "Enable x86 ASM related options" ${ASM_DEFAULT})
Rafael Kitover's avatar
Rafael Kitover committed
79

80
81
# The ARM ASM core seems to be very buggy, see #98 and #54. Default to it being
# OFF for the time being, until it is either fixed or replaced.
82
option(ENABLE_ASM_CORE "Enable x86 ASM CPU cores" OFF)
83

84
85
86
if(ENABLE_ASM_CORE)
    message(WARNING "!!!!!! The x86 ASM cores are considered buggy and dangerous, use at your own risk. !!!!!!")
endif()
87

88
89
set(ASM_SCALERS_DEFAULT ${ENABLE_ASM})
set(MMX_DEFAULT ${ENABLE_ASM})
Rafael Kitover's avatar
Rafael Kitover committed
90

91
option(ENABLE_ASM_SCALERS "Enable x86 ASM graphic filters" ${ASM_SCALERS_DEFAULT})
Rafael Kitover's avatar
Rafael Kitover committed
92
93

if(ENABLE_ASM_SCALERS)
94
95
    option(ENABLE_MMX "Enable MMX" ${MMX_DEFAULT})
endif()
Rafael Kitover's avatar
Rafael Kitover committed
96

97
98
option(ENABLE_LINK "Enable GBA linking functionality" ON)
option(ENABLE_LIRC "Enable LIRC support" OFF)
Rafael Kitover's avatar
Rafael Kitover committed
99

100
101
# currently completely broken
set(FFMPEG_DEFAULT OFF)
Rafael Kitover's avatar
Rafael Kitover committed
102

103
104
105
if(WIN32 AND NOT (MINGW AND MSYS))
    set(FFMPEG_DEFAULT OFF)
endif()
Rafael Kitover's avatar
Rafael Kitover committed
106
107
108

option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT})

109
set(LTO_DEFAULT ON)
110

111
if(WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64)
112
    # lto produces buggy binaries for 64 bit win32
113
114
    set(LTO_DEFAULT OFF)
endif()
115

116
option(ENABLE_LTO "Compile with Link Time Optimization (gcc and clang only)" ${LTO_DEFAULT})
117

Su Yong's avatar
Su Yong committed
118
if(MSVC)
119
120
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
Su Yong's avatar
Su Yong committed
121

122
123
124
125
option(ENABLE_GBA_LOGGING "Enable extended GBA logging" ON)
if(ENABLE_GBA_LOGGING)
   add_definitions(-DGBA_LOGGING )
endif()
squall-leonhart's avatar
squall-leonhart committed
126
if(ENABLE_MMX)
127
128
  add_definitions(-DMMX)
endif()
bgk's avatar
bgk committed
129
130

# The SDL port can't be built without debugging support
131
132
133
if(NOT ENABLE_DEBUGGER AND ENABLE_SDL)
        message(SEND_ERROR "The SDL port can't be built without debugging support")
endif()
n-a-c-h's avatar
n-a-c-h committed
134

135
136
137
138
139
140
141
# this has to run after the toolchain is initialized so it can't be in
# Win32deps.cmake
if(MINGW)
    include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-include")
    include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
endif()

Rafael Kitover's avatar
Rafael Kitover committed
142
143
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
144
145
    include(GitTagVersion)
    git_version(VERSION REVISION VERSION_RELEASE)
Rafael Kitover's avatar
Rafael Kitover committed
146
147
148
149
150

    # only use the plugin to tie the configure state to the sha to force rebuilds
    # of files that depend on version.h
    include(GetGitRevisionDescription)
    get_git_head_revision(REFSPEC COMMITHASH)
151
endif()
Rafael Kitover's avatar
Rafael Kitover committed
152

153
# no git or no tags, use ChangeLog
154
if(NOT VERSION)
155
156
    include(ChangeLogVersion)
    changelog_version(VERSION REVISION VERSION_RELEASE)
Rafael Kitover's avatar
Rafael Kitover committed
157
158
159
160
161
endif()

# generate version.h
include_directories(${CMAKE_BINARY_DIR})
configure_file("${CMAKE_SOURCE_DIR}/src/version.h.in" "${CMAKE_BINARY_DIR}/version.h" @ONLY)
n-a-c-h's avatar
n-a-c-h committed
162

163
164
165
166
167
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_definitions(-DDEBUG)
else()
    add_definitions(-DNDEBUG)
endif()
168

169
# hack for ninja in msys2
170
171
172
if(WIN32 AND CMAKE_GENERATOR STREQUAL Ninja AND (NOT $ENV{MSYSTEM} STREQUAL ""))
    set(MSYS ON)
endif()
173

174
# Add support for Homebrew, MacPorts and Fink on OS X
175
176
177
if(APPLE)
    include(MacPackageManagers)
endif()
178
179

# We do not support amd64 asm yet
180
181
182
if(AMD64 AND (ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS OR ENABLE_MMX))
    message(FATAL_ERROR "The options ASM_CORE, ASM_SCALERS and MMX are not supported on AMD64 yet.")
endif()
183

184
185
186
187
if(ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS)
    enable_language(ASM_NASM)
    set(ASM_ENABLED ON)
endif()
bgk's avatar
bgk committed
188

shuffle2's avatar
shuffle2 committed
189
# Look for some dependencies using CMake scripts
190
191
192
find_package(ZLIB REQUIRED)
find_package(OpenGL REQUIRED)
find_package(PNG REQUIRED)
Rafael Kitover's avatar
Rafael Kitover committed
193

194
195
196
if(EXISTS /etc/redhat-release)
    set(FEDORA_HOST ON)
endif()
Rafael Kitover's avatar
Rafael Kitover committed
197

198
199
200
if((APPLE AND NOT MACPORTS) OR (WIN32 AND FEDORA_HOST))
    set(SDL2_STATIC ON)
endif()
201

202
203
204
if(WIN32 AND SDL2_STATIC)
    set(SDL2_BUILDING_LIBRARY TRUE) # try not to link SDL2main
endif()
205

206
207
find_package(SDL2 REQUIRED)
add_definitions(${SDL2_DEFINITIONS})
bgk's avatar
bgk committed
208

209
if(ENABLE_LINK)
Rafael Kitover's avatar
Rafael Kitover committed
210
    # msys2 does not have static sfml libs atm
211
    # while on mxe we use static libs
212
    if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe) AND NOT CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)
213
        set(SFML_STATIC_LIBRARIES TRUE)
Rafael Kitover's avatar
Rafael Kitover committed
214
    endif()
215
216
    find_package(SFML 2 COMPONENTS network system REQUIRED)
endif()
Rafael Kitover's avatar
Rafael Kitover committed
217

218
# set the standard libraries all ports use
219
set(VBAMCORE_LIBS
220
221
    vbamcore
    fex
222
    ${SDL2_LIBRARY}
223
    ${SFML_LIBRARIES}
224
225
    ${OPENGL_LIBRARIES}
    ${ZLIB_LIBRARY}
226
227
    ${PNG_LIBRARY}
)
bgk's avatar
bgk committed
228

squall-leonhart's avatar
squall-leonhart committed
229
if(ENABLE_FFMPEG)
230
    find_package(PkgConfig REQUIRED)
squall-leonhart's avatar
squall-leonhart committed
231

232
    pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libswscale libavutil)
233
234
235
236
237
238
239
240
241
242
243
244

    if(FFMPEG_STATIC)
        set(FFMPEG_LIBRARIES ${FFMPEG_STATIC_LIBRARIES})
        set(FFMPEG_LDFLAGS   ${FFMPEG_STATIC_LDFLAGS} ${FFMPEG_STATIC_OTHER_LDFLAGS})

        if(APPLE)
            set(FFMPEG_LDFLAGS ${FFMPEG_LDFLAGS} -framework CoreText -framework ApplicationServices)
        endif()
    else()
        set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES})
        set(FFMPEG_LDFLAGS   ${FFMPEG_LDFLAGS} ${FFMPEG_OTHER_LDFLAGS})
    endif()
245
endif()
squall-leonhart's avatar
squall-leonhart committed
246
247

if(NOT ENABLE_FFMPEG)
248
249
  add_definitions(-DNO_FFMPEG)
endif()
squall-leonhart's avatar
squall-leonhart committed
250

251
252
253
254
255
if(ENABLE_LIRC)
        set(WITHLIRC 1)
else()
        set(WITHLIRC 0)
endif()
n-a-c-h's avatar
n-a-c-h committed
256

257
include(GNUInstallDirs)
n-a-c-h's avatar
n-a-c-h committed
258
259

# C defines
260
261
add_definitions(-DHAVE_NETINET_IN_H -DHAVE_ARPA_INET_H -DHAVE_ZLIB_H -DFINAL_VERSION -DSDL -DUSE_OPENGL -DSYSCONF_INSTALL_DIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" -DWITH_LIRC=${WITHLIRC})
add_definitions(-DPKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam" -DPACKAGE=)
n-a-c-h's avatar
n-a-c-h committed
262

263
if(ENABLE_LINK)
264
    # IPC linking code needs sem_timedwait which can be either in librt or pthreads
265
266
267
268
269
270
    if(NOT WIN32)
        find_library(RT_LIB rt)
        if(RT_LIB)
           set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${RT_LIB})
           set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${RT_LIB})
        endif()
271
272
    endif()

273
274
275
276
277
278
279
280
281
    if(NOT WIN32)
        find_library(PTHREAD_LIB pthread)
        if(PTHREAD_LIB)
           set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${PTHREAD_LIB})
           set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${PTHREAD_LIB})
        endif()
    elseif(MINGW)
       set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -lpthread)
       set(VBAMCORE_LIBS ${VBAMCORE_LIBS} -lpthread)
282
283
284
285
286
287
288
289
290
291
    endif()

    include(CheckFunctionExists)
    check_function_exists(sem_timedwait SEM_TIMEDWAIT)
    if(SEM_TIMEDWAIT)
        add_definitions(-DHAVE_SEM_TIMEDWAIT)
    endif()
else()
    add_definitions(-DNO_LINK)
endif()
bgk's avatar
bgk committed
292

293
# The debugger is enabled by default
294
295
296
297
298
if(NOT ENABLE_DEBUGGER)
    add_definitions(-DNO_DEBUGGER)
else()
    add_definitions(-DBKPT_SUPPORT)
endif()
299

n-a-c-h's avatar
n-a-c-h committed
300
# The ASM core is disabled by default because we don't know on which platform we are
301
302
303
if(NOT ENABLE_ASM_CORE)
    add_definitions(-DC_CORE)
endif()
n-a-c-h's avatar
n-a-c-h committed
304

305
306
option(ENABLE_NLS "Enable translations" ${NLS_DEFAULT})

bgk's avatar
bgk committed
307
# Enable internationalization
308
309
310
311
if(ENABLE_NLS)
    set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
    add_definitions(-DENABLE_NLS)
    add_definitions(-DLOCALEDIR="${LOCALEDIR}")
312
    # for now, only GBALink.cpp uses gettext() directly
313
    if(APPLE)
314
        # use Homebrew gettext if available
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
        if(EXISTS "/usr/local/opt/gettext")
            set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH};/usr/local/opt/gettext/include")
            set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};/usr/local/opt/gettext/lib")
            set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};/usr/local/opt/gettext/bin")
        endif()
    endif()
    if(ENABLE_LINK)
        find_path(LIBINTL_INC libintl.h)
        find_library(LIBINTL_LIB intl)
        find_library(LIBICONV_LIB iconv)
        if(LIBINTL_LIB)
            set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBINTL_LIB})
            set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${LIBINTL_LIB})
        endif()
        if(LIBICONV_LIB)
            set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBICONV_LIB})
            set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${LIBICONV_LIB})
        endif()
        include(CheckFunctionExists)
        check_function_exists(gettext GETTEXT_FN)
        if(NOT (LIBINTL_INC OR GETTEXT_FN))
            message(FATAL_ERROR "NLS requires libintl/gettext")
        endif()
        include_directories(${LIBINTL_INC})
    endif()
endif()
bgk's avatar
bgk committed
341

342
343
344
include(ProcessorCount)
ProcessorCount(num_cpus)

345
346
347
348
349
# Compiler stuff

if(CMAKE_C_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
    include(LLVMToolchain)
endif()
350

351
352
353
354
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
    set(LTO_FLAGS "")
    if(ENABLE_LTO)
        if(CMAKE_COMPILER_IS_GNUCXX)
355
            if(num_cpus GREATER 1)
356
                set(LTO_FLAGS -flto=${num_cpus} -ffat-lto-objects)
357
            else()
358
                set(LTO_FLAGS -flto -ffat-lto-objects)
359
            endif()
360
361
362
363
        else()
            set(LTO_FLAGS -flto)
        endif()
    endif()
Rafael Kitover's avatar
Rafael Kitover committed
364

365
366
367
368
369
370
    unset(MY_C_OPT_FLAGS)

    if(X86_32 OR AMD64)
        set(MY_C_OPT_FLAGS -mfpmath=sse -msse2)
    endif()

371
    # common optimization flags
372
373
374
    if(NOT (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3))
        set(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -O2 -fomit-frame-pointer ${LTO_FLAGS})
    else()
375
        # LTO and -fomit-frame-pointer generate broken binaries on Lion with XCode 4.2 tools
376
377
        set(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -O2)
    endif()
378
379

    # only use -mtune=generic on PC architectures
380
381
382
    if(X86_32 OR AMD64)
        set(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -mtune=generic)
    endif()
383
 
384
    # common debug flags
385
    if(CMAKE_COMPILER_IS_GNUCXX)
386
        set(MY_C_DBG_FLAGS -ggdb3 -Og -fno-omit-frame-pointer)
387
    else()
388
389
390
391
392
393
394
395
396
397
398
399
400
401
        set(MY_C_DBG_FLAGS -g -fno-omit-frame-pointer)
    endif()

    if(ENABLE_ASAN)
        string(TOLOWER ${CMAKE_BUILD_TYPE} build)
        if(NOT build STREQUAL "debug")
            message(FATAL_ERROR "asan requires debug build, set -DCMAKE_BUILD_TYPE=Debug")
        endif()

        string(TOLOWER ${ENABLE_ASAN} SANITIZER)
        if(SANITIZER STREQUAL "on" OR SANITIZER STREQUAL "true")
            set(SANITIZER address)
        endif()
        set(MY_C_DBG_FLAGS ${MY_C_DBG_FLAGS} -fsanitize=${SANITIZER} -lasan)
402
    endif()
403

404
    # common flags
405
    set(MY_C_FLAGS -pipe -Wformat -Wformat-security -D_FORTIFY_SOURCE=2 -feliminate-unused-debug-types)
406

407
    if(NOT (WIN32 OR X86_32)) # inline asm is not allowed with -fPIC
408
409
        set(MY_C_FLAGS ${MY_C_FLAGS} -fPIC)
    endif()
410

411
    include(CheckCXXCompilerFlag)
412

413
    # check if ssp flags are supported for this version of gcc
414
    if(CMAKE_COMPILER_IS_GNUCXX)
415
416
        if(ENABLE_SSP)
            check_cxx_compiler_flag(-fstack-protector-strong  F_STACK_PROTECTOR_STRONG_FLAG)
417

418
419
            if(F_STACK_PROTECTOR_STRONG_FLAG)
                set(MY_C_FLAGS ${MY_C_FLAGS} -fstack-protector-strong)
420

421
                check_cxx_compiler_flag("--param ssp-buffer-size=4" SSP_BUFFER_SIZE_FLAG)
422

423
424
425
426
427
                if(SSP_BUFFER_SIZE_FLAG)
                    # we do not add it to MY_C_FLAGS because this breaks things like CMAKE_REQUIRED_LIBRARIES
                    # which misinterpret compiler flags without leading dashes
                    add_compile_options(--param ssp-buffer-size=4)
                endif()
428
429
            endif()
        endif()
430

431
432
433
434
435
436
437

        set(MY_C_FLAGS ${MY_C_FLAGS} -fopenmp)
    endif()

    check_cxx_compiler_flag(-fdiagnostics-color=auto COMPILER_COLOR_OUTPUT)
    if(COMPILER_COLOR_OUTPUT)
        add_compile_options(-fdiagnostics-color=auto)
438
    endif()
439

440
441
442
443
444
445
446
447
448
    if(MINGW)
        set(MY_C_FLAGS ${MY_C_FLAGS} -static-libgcc -static-libstdc++)
    endif()

    if(CMAKE_BUILD_TYPE STREQUAL Debug)
        set(MY_C_FLAGS   ${MY_C_FLAGS}   ${MY_C_DBG_FLAGS} -Wall -Wextra)
    else()
        set(MY_C_FLAGS   ${MY_C_FLAGS}   ${MY_C_OPT_FLAGS} -Wno-error)
    endif()
449

450
451
452
    foreach(C_COMPILE_FLAG ${MY_C_FLAGS})
        add_compile_options(${C_COMPILE_FLAG})
    endforeach()
453

454
    set(MY_CXX_FLAGS -std=gnu++11 -fexceptions)
455

456
457
458
    foreach(ARG ${MY_CXX_FLAGS})
        set(MY_CXX_FLAGS_STR "${MY_CXX_FLAGS_STR} ${ARG}")
    endforeach()
459

460
461
462
    # These must be set for C++ only, and we can't use generator expressions in
    # ADD_COMPILE_OPTIONS because that's a cmake 3.3 feature and we need 2.8.12
    # compat for Ubuntu 14.
463
    string(REGEX REPLACE "<FLAGS>" "<FLAGS> ${MY_CXX_FLAGS_STR} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT})
464

465
466
467
    foreach(ARG ${MY_C_FLAGS})
        set(MY_C_FLAGS_STR "${MY_C_FLAGS_STR} ${ARG}")
    endforeach()
468
469

    # need all flags for linking, because of -flto etc.
470
471
    set(CMAKE_C_LINK_EXECUTABLE   "${CMAKE_C_LINK_EXECUTABLE}   ${MY_C_FLAGS_STR}")
    set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_FLAGS_STR}")
472

473
    # for the gcc -fstack-protector* flags we need libssp
474
    # we also have to use the gcc- binutils for LTO to work
475
476
477
478
    if(CMAKE_COMPILER_IS_GNUCXX)
        if(ENABLE_LTO)
            include(UseGCCBinUtilsWrappers)
        endif()
479

480
481
482
        if(WIN32)
            set(SSP_STATIC ON)
        endif()
483

484
485
        if(ENABLE_SSP)
            find_package(SSP)
486

487
488
489
            if(SSP_LIBRARY)
                set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} ${SSP_LIBRARY})
            endif()
490
        endif()
491

492
493
494
495
496
497
498
        set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} -Wl,-allow-multiple-definition)

        if(CMAKE_PREFIX_PATH)
            list(GET CMAKE_PREFIX_PATH 0 prefix_path_first)
            set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} "-Wl,-rpath-link=${prefix_path_first}/lib")
        endif()
    endif()
499
500

    # set linker flags
501
502
503
    foreach(ARG ${MY_C_LINKER_FLAGS})
        set(MY_C_LINKER_FLAGS_STR "${MY_C_LINKER_FLAGS_STR} ${ARG}")
    endforeach()
504

505
506
507
    set(CMAKE_C_LINK_EXECUTABLE   "${CMAKE_C_LINK_EXECUTABLE}   ${MY_C_LINKER_FLAGS_STR}")
    set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}")
endif()
508

509
# Assembler flags
n-a-c-h's avatar
n-a-c-h committed
510

511
512
513
if(ASM_ENABLED)
    string(REGEX REPLACE "<FLAGS>" "-I${CMAKE_SOURCE_DIR}/src/filters/hq/asm/ -O1 -w-orphan-labels" CMAKE_ASM_NASM_COMPILE_OBJECT ${CMAKE_ASM_NASM_COMPILE_OBJECT})
endif()
514

515
516
517
518
519
if(APPLE)
    add_definitions(-DMACHO)
elseif("${CMAKE_SYSTEM}" MATCHES "Linux")
    add_definitions(-DELF)
endif()
520

521
522
523
if(AMD64)
    add_definitions(-D__AMD64__)
endif()
524

525
add_subdirectory (fex)
shuffle2's avatar
shuffle2 committed
526

527
set(SRC_MAIN
n-a-c-h's avatar
n-a-c-h committed
528
    src/Util.cpp
529
530
531
    src/common/ConfigManager.cpp
    src/common/dictionary.c
    src/common/iniparser.c
bgk's avatar
bgk committed
532
533
    src/common/Patch.cpp
    src/common/memgzio.c
squall-leonhart's avatar
squall-leonhart committed
534
    src/common/SoundSDL.cpp
n-a-c-h's avatar
n-a-c-h committed
535
536
)

Su Yong's avatar
Su Yong committed
537
if(MSVC)
538
539
	set(SRC_MAIN ${SRC_MAIN} "dependencies/msvc/getopt.c")
endif()
Su Yong's avatar
Su Yong committed
540

541
set(HDR_MAIN
542
543
544
545
546
547
548
549
550
551
552
553
    src/System.h
    src/Util.h
    src/common/array.h
    src/common/ConfigManager.h
    src/common/dictionary.h
    src/common/iniparser.h
    src/common/memgzio.h
    src/common/Port.h
    src/common/SoundDriver.h
    src/common/SoundSDL.h
)

Su Yong's avatar
Su Yong committed
554
if(MSVC)
555
556
	set(HDR_MAIN ${HDR_MAIN} "dependencies/msvc/getopt.h")
endif()
Su Yong's avatar
Su Yong committed
557

squall-leonhart's avatar
squall-leonhart committed
558
if(ENABLE_FFMPEG)
559
560
561
    set(SRC_MAIN ${SRC_MAIN} src/common/ffmpeg.cpp)
    set(HDR_MAIN ${HDR_MAIN} src/common/ffmpeg.h)
endif()
squall-leonhart's avatar
squall-leonhart committed
562

563
if(ENABLE_NLS)
564
565
    set(HDR_MAIN ${HDR_MAIN} src/NLS.h)
endif()
566

567
set(SRC_GBA
bgk's avatar
bgk committed
568
    src/gba/agbprint.cpp
569
    src/gba/bios.cpp
570
    src/gba/BreakpointStructures.cpp
571
    src/gba/Cheats.cpp
squall-leonhart's avatar
squall-leonhart committed
572
    src/gba/CheatSearch.cpp
573
574
    src/gba/debugger-expr-lex.cpp
    src/gba/debugger-expr-yacc.cpp
575
    src/gba/EEprom.cpp
576
    src/gba/ereader.cpp
577
    src/gba/Flash.cpp
bgk's avatar
bgk committed
578
579
    src/gba/GBA.cpp
    src/gba/GBAGfx.cpp
shuffle2's avatar
shuffle2 committed
580
581
    src/gba/GBALink.cpp
    src/gba/GBASockClient.cpp
bgk's avatar
bgk committed
582
583
    src/gba/GBA-thumb.cpp
    src/gba/GBA-arm.cpp
bgk's avatar
bgk committed
584
    src/gba/gbafilter.cpp
585
586
587
588
589
590
591
592
593
594
    src/gba/Globals.cpp
    src/gba/Mode0.cpp
    src/gba/Mode1.cpp
    src/gba/Mode2.cpp
    src/gba/Mode3.cpp
    src/gba/Mode4.cpp
    src/gba/Mode5.cpp
    src/gba/RTC.cpp
    src/gba/Sound.cpp
    src/gba/Sram.cpp
n-a-c-h's avatar
n-a-c-h committed
595
596
)

597
set(HDR_GBA
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
    src/gba/agbprint.h
    src/gba/bios.h
    src/gba/BreakpointStructures.h
    src/gba/Cheats.h
    src/gba/CheatSearch.h
    src/gba/debugger-expr-yacc.hpp
    src/gba/EEprom.h
    src/gba/ereader.h
    src/gba/Flash.h
    src/gba/GBA.h
    src/gba/GBAcpu.h
    src/gba/gbafilter.h
    src/gba/GBAGfx.h
    src/gba/GBAinline.h
    src/gba/GBALink.h
    src/gba/GBASockClient.h
    src/gba/Globals.h
    src/gba/RTC.h
    src/gba/Sound.h
    src/gba/Sram.h
)

620
set(SRC_GB
bgk's avatar
bgk committed
621
622
623
624
625
626
627
628
629
    src/gb/GB.cpp
    src/gb/gbCheats.cpp
    src/gb/gbDis.cpp
    src/gb/gbGfx.cpp
    src/gb/gbGlobals.cpp
    src/gb/gbMemory.cpp
    src/gb/gbPrinter.cpp
    src/gb/gbSGB.cpp
    src/gb/gbSound.cpp
630
631
)

632
set(HDR_GB
633
634
635
636
637
638
639
640
641
642
643
    src/gb/gb.h
    src/gb/gbCheats.h
    src/gb/gbCodes.h
    src/gb/gbCodesCB.h
    src/gb/gbGlobals.h
    src/gb/gbMemory.h
    src/gb/gbPrinter.h
    src/gb/gbSGB.h
    src/gb/gbSound.h
)

644
set(SRC_APU
645
646
647
648
649
650
    src/apu/Blip_Buffer.cpp
    src/apu/Effects_Buffer.cpp
    src/apu/Gb_Apu.cpp
    src/apu/Gb_Apu_State.cpp
    src/apu/Gb_Oscs.cpp
    src/apu/Multi_Buffer.cpp
n-a-c-h's avatar
n-a-c-h committed
651
652
)

653
set(HDR_APU
654
655
656
657
658
659
660
661
662
663
    src/apu/blargg_common.h #Unused(?) but in the VS projects
    src/apu/blargg_config.h #Unused(?) but in the VS projects
    src/apu/blargg_source.h
    src/apu/Blip_Buffer.h
    src/apu/Effects_Buffer.h
    src/apu/Gb_Apu.h
    src/apu/Gb_Oscs.h
    src/apu/Multi_Buffer.h
)

664
set(SRC_SDL
n-a-c-h's avatar
n-a-c-h committed
665
666
667
    src/sdl/SDL.cpp
    src/sdl/filters.cpp
    src/sdl/text.cpp
bgk's avatar
SDL:    
bgk committed
668
    src/sdl/inputSDL.cpp
bgk's avatar
SDL:    
bgk committed
669
670
671
    src/sdl/expr.cpp
    src/sdl/exprNode.cpp
    src/sdl/expr-lex.cpp
n-a-c-h's avatar
n-a-c-h committed
672
673
)

674
set(HDR_SDL
675
676
677
678
679
680
681
    src/sdl/filters.h
    src/sdl/text.h
    src/sdl/inputSDL.h
    src/sdl/expr.cpp.h
    src/sdl/exprNode.h
)

682
set(SRC_FILTERS
683
684
685
686
687
688
689
    src/filters/2xSaI.cpp
    src/filters/admame.cpp
    src/filters/bilinear.cpp
    src/filters/hq2x.cpp
    src/filters/interframe.cpp
    src/filters/pixel.cpp
    src/filters/scanline.cpp
690
    src/filters/simpleFilter.cpp
691
692
    src/filters/xbrzfilter.cpp
    src/filters/xBRZ/xbrz.cpp
693
694
)

695
set(HDR_FILTERS
696
697
698
699
700
701
702
    src/filters/hq2x.h
    src/filters/interp.h
    src/filters/lq2x.h
    src/filters/xBRZ/config.h
    src/filters/xBRZ/xbrz.h
)

703
set(SRC_HQ_C
704
    src/filters/hq/c/hq_implementation.cpp
n-a-c-h's avatar
n-a-c-h committed
705
706
)

707
set(HDR_HQ_C
708
709
710
711
712
713
    src/filters/hq/c/hq3x_pattern.h
    src/filters/hq/c/hq4x_pattern.h
    src/filters/hq/c/hq_base.h
    src/filters/hq/c/hq_shared.h
)

714
set(SRC_HQ_ASM
715
716
717
718
719
    src/filters/hq/asm/hq3x_16.asm
    src/filters/hq/asm/hq3x_32.asm
    src/filters/hq/asm/hq4x_16.asm
    src/filters/hq/asm/hq4x_32.asm
    src/filters/hq/asm/hq3x32.cpp
n-a-c-h's avatar
n-a-c-h committed
720
721
)

722
723
724
725
726
727
728
729
730
731
732
733
734
if(ENABLE_ASM_SCALERS)
    set(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_ASM})
    if(ENABLE_MMX)
        set(SRC_FILTERS ${SRC_FILTERS} src/filters/2xSaImmx.asm)
    endif()
else()
    set(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_C})
    set(HDR_FILTERS ${HDR_FILTERS} ${HDR_HQ_C})
    add_definitions(-DNO_ASM)
endif()

if(ENABLE_DEBUGGER)
    set(SRC_DEBUGGER
735
736
737
        src/gba/armdis.cpp
        src/gba/elf.cpp
        src/gba/remote.cpp
738
    )
739
    set(HDR_DEBUGGER
740
741
742
743
        src/gba/armdis.h
        src/gba/elf.h
        src/gba/remote.h
    )
744
endif()
745

746
include_directories(
bgk's avatar
bgk committed
747
    ${ZLIB_INCLUDE_DIR}
shuffle2's avatar
shuffle2 committed
748
    fex
spacy51's avatar
spacy51 committed
749
    ${PNG_INCLUDE_DIR}
750
    ${SDL2_INCLUDE_DIR}
n-a-c-h's avatar
n-a-c-h committed
751
752
)

753
754
if(ENABLE_FFMPEG)
    include_directories(
755
756
        ${FFMPEG_INCLUDE_DIRS}
    )
757
endif()
758

759
add_library(
n-a-c-h's avatar
n-a-c-h committed
760
    vbamcore
761
    STATIC
n-a-c-h's avatar
n-a-c-h committed
762
763
    ${PROJECT_SRCS}
    ${SRC_MAIN}
764
    ${HDR_MAIN}
bgk's avatar
bgk committed
765
    ${SRC_GBA}
766
    ${HDR_GBA}
bgk's avatar
bgk committed
767
    ${SRC_GB}
768
    ${HDR_GB}
769
    ${SRC_APU}
770
    ${HDR_APU}
771
    ${SRC_FILTERS}
772
    ${HDR_FILTERS}
773
    ${SRC_DEBUGGER}
774
    ${HDR_DEBUGGER}
n-a-c-h's avatar
n-a-c-h committed
775
)
EoD's avatar
EoD committed
776
777
set_property(TARGET vbamcore PROPERTY CXX_STANDARD 11)
set_property(TARGET vbamcore PROPERTY CXX_STANDARD_REQUIRED ON)
n-a-c-h's avatar
n-a-c-h committed
778

779
780
if(ENABLE_SDL)
    add_executable(
n-a-c-h's avatar
n-a-c-h committed
781
782
783
        vbam
        WIN32
        ${SRC_SDL}
784
        ${HDR_SDL}
n-a-c-h's avatar
n-a-c-h committed
785
    )
EoD's avatar
EoD committed
786
787
    set_property(TARGET vbam PROPERTY CXX_STANDARD 11)
    set_property(TARGET vbam PROPERTY CXX_STANDARD_REQUIRED ON)
n-a-c-h's avatar
n-a-c-h committed
788

789
790
791
    if(WIN32)
        set(WIN32_LIBRARIES wsock32 ws2_32)
    endif()
bgk's avatar
bgk committed
792

793
794
795
    if(ENABLE_LIRC)
        set(LIRC_CLIENT_LIBRARY lirc_client)
    endif()
796

797
    target_link_libraries(
n-a-c-h's avatar
n-a-c-h committed
798
        vbam
799
        ${VBAMCORE_LIBS}
bgk's avatar
bgk committed
800
        ${WIN32_LIBRARIES}
801
        ${LIRC_CLIENT_LIBRARY}
n-a-c-h's avatar
n-a-c-h committed
802
    )
803
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/vbam${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
Mystro256's avatar
Mystro256 committed
804

805
806
    if(WIN32)
        install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/sdl/vbam.cfg-example
807
                DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}
Mystro256's avatar
Mystro256 committed
808
                RENAME vbam.cfg)
809
810
    else()
        install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/sdl/vbam.cfg-example
811
                DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}
Mystro256's avatar
Mystro256 committed
812
                RENAME vbam.cfg)
813
814
    endif()
endif()
n-a-c-h's avatar
n-a-c-h committed
815

816
if(ENABLE_WX)
817
    add_subdirectory(src/wx)
818
819
    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/visualboyadvance-m${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
endif()
820

821
if(ENABLE_WX)
bgk's avatar
bgk committed
822
    # Native Language Support
823
    if(ENABLE_NLS)
bgk's avatar
bgk committed
824
        add_subdirectory(po)
825
826
827
    endif()
endif()
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/vba-over.ini DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/vbam)
828
829

# manual pages
830
831
832
833
834
835
836
837
if(UNIX)
    if(ENABLE_SDL)
        install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/debian/vbam.6 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man6)
    endif()
    if(ENABLE_WX)
        install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/debian/visualboyadvance-m.6 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man6)
    endif()
endif()
838

839
# linux data and icon files
840
841
842
843
844
845
846
847
848
if(NOT WIN32 AND NOT APPLE)
    if(ENABLE_WX)
        install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/wxvbam.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
        install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/wxvbam.appdata.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/appdata)
        install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/icons/sizes/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor)
    endif()
endif()

set(CPACK_GENERATOR "ZIP")
849
set(CPACK_SOURCE_GENERATOR "TGZ")
850
851
852
set(CPACK_PACKAGE_VERSION_MAJOR "2")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0-Git-" ${COMMITHASH})
DoctorWho11's avatar
DoctorWho11 committed
853
list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/dependencies")
854
include(CPack)