CMakeLists.txt 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. cmake_minimum_required(VERSION 2.6)
  2. project(SUDM)
  3. # Set to true when using SUDM as a submodule of another project such that only the lib is compiled
  4. option(SUDM_AS_LIB "Build only lib" FALSE)
  5. # For now, you'll need to place said files in the appropriate test dir
  6. # TODO: move this elsewhere?
  7. option(TEST_COPYRIGHTED_FILES "Enable tests against copyrighted files" FALSE)
  8. if (NOT SUDM_AS_LIB)
  9. enable_testing()
  10. endif()
  11. # The version number
  12. set(VERSION_MAJOR 0)
  13. set(VERSION_MINOR 1)
  14. if (CMAKE_BUILD_TYPE STREQUAL "")
  15. # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
  16. # differentiation between debug and release builds.
  17. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
  18. endif ()
  19. if (NOT SUDM_AS_LIB)
  20. # On Linux gtest needs pthreads
  21. if (UNIX)
  22. find_package (Threads)
  23. endif()
  24. include_directories(
  25. ${CMAKE_CURRENT_SOURCE_DIR}/googlemock
  26. ${CMAKE_CURRENT_SOURCE_DIR}/googlemock/include
  27. ${CMAKE_CURRENT_SOURCE_DIR}/googlemock/gtest/include
  28. ${CMAKE_CURRENT_SOURCE_DIR}/googlemock/gtest
  29. )
  30. SET(gmock_src
  31. ${CMAKE_CURRENT_SOURCE_DIR}/googlemock/src/gmock-all.cc
  32. ${CMAKE_CURRENT_SOURCE_DIR}/googlemock/gtest/src/gtest-all.cc)
  33. add_library(gmock STATIC ${gmock_src})
  34. endif()
  35. if (MSVC)
  36. # Build cpp files on all cores
  37. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4")
  38. # can't use the "secure" versions as they're Windows specific
  39. add_definitions("/D\"_CRT_SECURE_NO_WARNINGS\"")
  40. add_definitions("/D\"_SCL_SECURE_NO_WARNINGS\"")
  41. add_definitions("/wd4290")
  42. else()
  43. # Enable C++11, you may need to use -std=c++0x if using an older gcc compiler
  44. if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  45. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  46. else()
  47. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-unused-parameter -fPIC -Wall -Weffc++ -pedantic")
  48. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-unused-parameter -fPIC -Wall")
  49. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wcast-align")
  50. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion")
  51. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdisabled-optimization")
  52. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfloat-equal -Wformat -Wformat=2")
  53. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-nonliteral -Wformat-security")
  54. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-y2k")
  55. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimport -Winit-self")
  56. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch")
  57. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunsafe-loop-optimizations -Wmissing-braces")
  58. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers -Wmissing-format-attribute")
  59. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn")
  60. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpacked -Wparentheses -Wpointer-arith")
  61. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wredundant-decls -Wreturn-type")
  62. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsequence-point -Wshadow -Wsign-compare -Wstack-protector")
  63. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default")
  64. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wswitch-enum -Wtrigraphs -Wuninitialized")
  65. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wtrigraphs -Wuninitialized")
  66. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunknown-pragmas -Wunreachable-code -Wunused")
  67. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-function -Wunused-label -Wunused-parameter")
  68. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-value -Wunused-variable -Wvariadic-macros")
  69. #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvolatile-register-var -Wwrite-strings")
  70. if (UNIX AND $ENV{COVERAGE}==1)
  71. message("Setting coverage compiler options")
  72. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0") # debug, no optimisation
  73. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") # enabling coverage
  74. endif()
  75. # we dont want high warning levels on 3rd party things since we won't be fixing those warnings
  76. set_source_files_properties(${gmock_src} PROPERTIES COMPILE_FLAGS -Wno-effc++)
  77. endif()
  78. endif()
  79. SET(source
  80. decompiler/sudm.cpp
  81. decompiler/sudm.h
  82. decompiler/decompiler_codegen.cpp
  83. decompiler/decompiler_codegen.h
  84. decompiler/control_flow.cpp
  85. decompiler/control_flow.h
  86. decompiler/decompiler_disassembler.cpp
  87. decompiler/decompiler_disassembler.h
  88. decompiler/decompiler_engine.h
  89. decompiler/graph.cpp
  90. decompiler/graph.h
  91. decompiler/instruction.cpp
  92. decompiler/instruction.h
  93. decompiler/objectFactory.h
  94. decompiler/refcounted.h
  95. decompiler/simple_disassembler.cpp
  96. decompiler/simple_disassembler.h
  97. decompiler/stack.h
  98. decompiler/unknown_opcode_exception.cpp
  99. decompiler/unknown_opcode_exception.h
  100. decompiler/value.cpp
  101. decompiler/value.h
  102. decompiler/wrongtype.h
  103. decompiler/scummv6/codegen.cpp
  104. decompiler/scummv6/codegen.h
  105. decompiler/scummv6/disassembler.cpp
  106. decompiler/scummv6/disassembler.h
  107. decompiler/scummv6/engine.cpp
  108. decompiler/scummv6/engine.h
  109. decompiler/ff7_field/ff7_field_disassembler.cpp
  110. decompiler/ff7_field/ff7_field_disassembler.h
  111. decompiler/ff7_field/ff7_field_engine.cpp
  112. decompiler/ff7_field/ff7_field_engine.h
  113. decompiler/ff7_field/ff7_field_codegen.cpp
  114. decompiler/ff7_field/ff7_field_codegen.h
  115. #decompiler/ff7_world/ff7_world_disassembler.cpp
  116. #decompiler/ff7_world/ff7_world_disassembler.h
  117. #decompiler/ff7_world/ff7_world_engine.cpp
  118. #decompiler/ff7_world/ff7_world_engine.h
  119. #decompiler/ff7_world/ff7_world_codegen.cpp
  120. #decompiler/ff7_world/ff7_world_codegen.h
  121. common/algorithm.h
  122. common/noncopyable.h
  123. common/scummsys.h
  124. common/str.cpp
  125. common/str.h
  126. common/util.h
  127. common/binaryreader.h
  128. common/lzs.h
  129. common/make_unique.h
  130. )
  131. find_package(Boost COMPONENTS program_options filesystem thread date_time system chrono REQUIRED)
  132. include_directories(
  133. ${Boost_INCLUDE_DIR}
  134. ${CMAKE_CURRENT_SOURCE_DIR}
  135. ${CMAKE_CURRENT_SOURCE_DIR}/common
  136. ${CMAKE_CURRENT_SOURCE_DIR}/decompiler
  137. )
  138. add_definitions(-DBOOST_ALL_NO_LIB)
  139. add_definitions(-DBOOST_ALL_DYN_LINK)
  140. if (UNIX)
  141. add_definitions(-DPOSIX)
  142. endif()
  143. ADD_LIBRARY(Sudm_Lib STATIC ${source})
  144. if (NOT SUDM_AS_LIB)
  145. add_executable(Sudm
  146. decompiler/decompiler.cpp
  147. )
  148. target_link_libraries(Sudm Sudm_Lib ${Boost_LIBRARIES})
  149. set(safe_test_source
  150. decompiler/test/cfg_test.cpp
  151. decompiler/test/codegen.cpp
  152. decompiler/test/disassembler_test.cpp
  153. decompiler/test/disassembler/pasc.cpp
  154. decompiler/test/disassembler/pasc.h
  155. decompiler/test/disassembler/subopcode.cpp
  156. decompiler/test/disassembler/subopcode.h
  157. decompiler/test/main.cpp
  158. decompiler/test/ff7_field_disasm_all_opcodes_by_category_test.cpp
  159. decompiler/test/ff7_field_control_flow_test.cpp
  160. decompiler/test/ff7_field_dummy_formatter.h
  161. )
  162. set(unsafe_test_source
  163. )
  164. if (TEST_COPYRIGHTED_FILES)
  165. add_executable(Sudm_Test ${safe_test_source} ${unsafe_test_source})
  166. else()
  167. add_executable(Sudm_Test ${safe_test_source})
  168. endif()
  169. target_link_libraries(Sudm_Test Sudm_Lib gmock ${Boost_LIBRARIES})
  170. add_test(NAME Sudm_Test COMMAND Sudm_Test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  171. endif()