diff --git a/.gitignore b/.gitignore index 1c3b425..33027a1 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,7 @@ build/uwp/tic/packages/ build/windows/studio/x64/ build/windows/sdl-gpu/x64/ .vs/ +CMakeFiles/ +lib/ +*.cmake +CMakeCache.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index f921052..a22bdf2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,30 @@ -project(TIC-80) +cmake_minimum_required(VERSION 3.9) + +project(TIC-80 C) +message("Building for target : ${CMAKE_SYSTEM_NAME}") set(CMAKE_C_STANDARD 99) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include(FindPkgConfig) +if(NOT PKG_CONFIG_FOUND AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + message(FATAL_ERROR "We need pkg-config to compile this project") +endif() + +#platform specific includes +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + pkg_check_modules(GTK REQUIRED gtk+-3.0) +endif() + ################################ # LUA ################################ @@ -139,6 +162,7 @@ if(WIN32) set(HAVE_LIBC TRUE) endif() +set(SDL_SHARED OFF) set(SDL_STATIC ON) add_subdirectory(3rd-party/SDL2-2.0.7) @@ -199,7 +223,15 @@ target_include_directories(sdlgpu PRIVATE 3rd-party/sdl-gpu/src/externals/stb_im target_include_directories(sdlgpu PRIVATE 3rd-party/SDL2-2.0.7/include) add_dependencies(sdlgpu SDL2-static) -target_link_libraries(sdlgpu SDL2-static opengl32) +target_link_libraries(sdlgpu SDL2-static) + +if(WIN32) + target_link_libraries(sdlgpu opengl32) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") +target_link_libraries(sdlgpu GL) +endif() ################################ # SDL NET @@ -215,7 +247,9 @@ set(SDLNET_SRC add_library(sdlnet STATIC ${SDLNET_SRC}) target_include_directories(sdlnet PRIVATE 3rd-party/SDL2-2.0.7/include) -target_link_libraries(sdlnet ws2_32) +if(WIN32) + target_link_libraries(sdlnet ws2_32) +endif() ################################ # ZLIB @@ -283,6 +317,11 @@ else() add_executable(tic80 ${TIC80_SRC}) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_include_directories(tic80 PRIVATE ${GTK_INCLUDE_DIRS}) + target_link_libraries(tic80 ${GTK_LIBRARIES}) +endif() + target_include_directories(tic80 PRIVATE include) target_include_directories(tic80 PRIVATE 3rd-party/SDL2-2.0.7/include) target_include_directories(tic80 PRIVATE 3rd-party/sdl-gpu/include)