ref: 8101009bbacb0feadead89ef36419ba15a33b171
parent: f8810f763c304449fbe81d792da13013aadb6e8d
author: Alex Mayfield <[email protected]>
date: Fri May 4 13:46:19 EDT 2018
CMake now works on Linux It uses pkg-config to obtain hints about where the libraries are.
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,10 +1,11 @@
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-cmake_minimum_required(VERSION 3.9.3)
+cmake_minimum_required(VERSION 3.7.2)
project("Chocolate Doom" VERSION 3.0.0 LANGUAGES C)
# AC_INIT variables
set(PACKAGE_NAME "${PROJECT_NAME}")
+set(PACKAGE_TARNAME "chocolate-doom")
set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
string(REGEX REPLACE " Doom$" "" PACKAGE_SHORTNAME "${PACKAGE_NAME}")
@@ -12,6 +13,10 @@
find_package(SDL2 2.0.1)
find_package(SDL2_mixer 2.0.0)
find_package(SDL2_net 2.0.0)
+
+include(CheckFunctionExists)
+check_function_exists(strcasecmp HAVE_DECL_STRCASECMP)
+check_function_exists(strncasecmp HAVE_DECL_STRNCASECMP)
# Without a hyphen. This is used for the bash-completion scripts.
string(TOLOWER "${PACKAGE_SHORTNAME}" PROGRAM_SPREFIX)
--- a/cmake/FindSDL2.cmake
+++ b/cmake/FindSDL2.cmake
@@ -26,6 +26,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Currently works with the following generators:
+# - Unix Makefiles
+# - Ninja
# - Visual Studio
# Cache variable that allows you to point CMake at a directory containing
@@ -32,9 +34,15 @@
# an extracted development library.
set(SDL2_DIR "${SDL2_DIR}" CACHE PATH "Location of SDL2 library directory")
+# Use pkg-config to find library locations in *NIX environments.
+find_package(PkgConfig QUIET)
+if(PKG_CONFIG_FOUND)
+ pkg_search_module(PC_SDL2 QUIET sdl2)
+endif()
+
# Find the include directory.
find_path(SDL2_INCLUDE_DIR "SDL_version.h"
- PATHS "${SDL2_DIR}/include")
+ HINTS "${SDL2_DIR}/include" ${PC_SDL2_INCLUDE_DIRS})
# Find the version. Taken and modified from CMake's FindSDL.cmake.
if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h")
@@ -56,14 +64,14 @@
# Find the SDL2 and SDL2main libraries
if(CMAKE_SIZEOF_VOID_P STREQUAL 8)
find_library(SDL2_LIBRARY "SDL2"
- PATHS "${SDL2_DIR}/lib/x64")
+ HINTS "${SDL2_DIR}/lib/x64" ${PC_SDL2_LIBRARY_DIRS})
find_library(SDL2_MAIN_LIBRARY "SDL2main"
- PATHS "${SDL2_DIR}/lib/x64")
+ HINTS "${SDL2_DIR}/lib/x64" ${PC_SDL2_LIBRARY_DIRS})
else()
find_library(SDL2_LIBRARY "SDL2"
- PATHS "${SDL2_DIR}/lib/x86")
+ HINTS "${SDL2_DIR}/lib/x86" ${PC_SDL2_LIBRARY_DIRS})
find_library(SDL2_MAIN_LIBRARY "SDL2main"
- PATHS "${SDL2_DIR}/lib/x86")
+ HINTS "${SDL2_DIR}/lib/x86" ${PC_SDL2_LIBRARY_DIRS})
endif()
set(SDL2_LIBRARIES "${SDL2_MAIN_LIBRARY}" "${SDL2_LIBRARY}")
@@ -78,6 +86,7 @@
# SDL2 imported target.
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "${PC_SDL2_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
IMPORTED_LOCATION "${SDL2_LIBRARY}")
--- a/cmake/FindSDL2_mixer.cmake
+++ b/cmake/FindSDL2_mixer.cmake
@@ -26,6 +26,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Currently works with the following generators:
+# - Unix Makefiles
+# - Ninja
# - Visual Studio
# Cache variable that allows you to point CMake at a directory containing
@@ -32,9 +34,15 @@
# an extracted development library.
set(SDL2_MIXER_DIR "${SDL2_MIXER_DIR}" CACHE PATH "Location of SDL2_mixer library directory")
+# Use pkg-config to find library locations in *NIX environments.
+find_package(PkgConfig QUIET)
+if(PKG_CONFIG_FOUND)
+ pkg_search_module(PC_SDL2_MIXER QUIET SDL2_mixer)
+endif()
+
# Find the include directory.
find_path(SDL2_MIXER_INCLUDE_DIR "SDL_mixer.h"
- PATHS "${SDL2_MIXER_DIR}/include")
+ HINTS "${SDL2_MIXER_DIR}/include" ${PC_SDL2_MIXER_INCLUDE_DIRS})
# Find the version. Taken and modified from CMake's FindSDL.cmake.
if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h")
@@ -56,10 +64,10 @@
# Find the library.
if(CMAKE_SIZEOF_VOID_P STREQUAL 8)
find_library(SDL2_MIXER_LIBRARY "SDL2_mixer"
- PATHS "${SDL2_MIXER_DIR}/lib/x64")
+ HINTS "${SDL2_MIXER_DIR}/lib/x64" ${PC_SDL2_MIXER_LIBRARY_DIRS})
else()
- find_library(SDL2_MIXER_LIBRARY "SDL2"
- PATHS "${SDL2_MIXER_DIR}/lib/x86")
+ find_library(SDL2_MIXER_LIBRARY "SDL2_mixer"
+ HINTS "${SDL2_MIXER_DIR}/lib/x86" ${PC_SDL2_MIXER_LIBRARY_DIRS})
endif()
include(FindPackageHandleStandardArgs)
@@ -73,6 +81,7 @@
# Imported target.
add_library(SDL2::mixer UNKNOWN IMPORTED)
set_target_properties(SDL2::mixer PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "${PC_SDL2_MIXER_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES SDL2::SDL2
IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}")
--- a/cmake/FindSDL2_net.cmake
+++ b/cmake/FindSDL2_net.cmake
@@ -26,6 +26,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Currently works with the following generators:
+# - Unix Makefiles
+# - Ninja
# - Visual Studio
# Cache variable that allows you to point CMake at a directory containing
@@ -32,9 +34,15 @@
# an extracted development library.
set(SDL2_NET_DIR "${SDL2_NET_DIR}" CACHE PATH "Location of SDL2_net library directory")
+# Use pkg-config to find library locations in *NIX environments.
+find_package(PkgConfig QUIET)
+if(PKG_CONFIG_FOUND)
+ pkg_search_module(PC_SDL2_NET QUIET SDL2_net)
+endif()
+
# Find the include directory.
find_path(SDL2_NET_INCLUDE_DIR "SDL_net.h"
- PATHS "${SDL2_NET_DIR}/include")
+ HINTS "${SDL2_NET_DIR}/include" ${PC_SDL2_NET_INCLUDE_DIRS})
# Find the version. Taken and modified from CMake's FindSDL.cmake.
if(SDL2_NET_INCLUDE_DIR AND EXISTS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h")
@@ -56,10 +64,10 @@
# Find the library.
if(CMAKE_SIZEOF_VOID_P STREQUAL 8)
find_library(SDL2_NET_LIBRARY "SDL2_net"
- PATHS "${SDL2_NET_DIR}/lib/x64")
+ HINTS "${SDL2_NET_DIR}/lib/x64" ${PC_SDL2_NET_LIBRARY_DIRS})
else()
- find_library(SDL2_NET_LIBRARY "SDL2"
- PATHS "${SDL2_NET_DIR}/lib/x86")
+ find_library(SDL2_NET_LIBRARY "SDL2_net"
+ HINTS "${SDL2_NET_DIR}/lib/x86" ${PC_SDL2_NET_LIBRARY_DIRS})
endif()
include(FindPackageHandleStandardArgs)
@@ -73,6 +81,7 @@
# Imported target.
add_library(SDL2::net UNKNOWN IMPORTED)
set_target_properties(SDL2::net PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "${PC_SDL2_NET_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_NET_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES SDL2::SDL2
IMPORTED_LOCATION "${SDL2_NET_LIBRARY}")
--- a/config.cmake.h
+++ b/config.cmake.h
@@ -1,3 +1,7 @@
#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@"
+#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@"
#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@"
#cmakedefine PROGRAM_PREFIX "@PROGRAM_PREFIX@"
+
+#cmakedefine01 HAVE_DECL_STRCASECMP
+#cmakedefine01 HAVE_DECL_STRNCASECMP
--- a/midiproc/CMakeLists.txt
+++ b/midiproc/CMakeLists.txt
@@ -1,4 +1,6 @@
-add_executable("${PROGRAM_PREFIX}midiproc" buffer.c buffer.h main.c proto.h)
-target_include_directories("${PROGRAM_PREFIX}midiproc"
- PRIVATE "../src/" "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries("${PROGRAM_PREFIX}midiproc" SDL2::SDL2main SDL2::mixer)
+if(WIN32)
+ add_executable("${PROGRAM_PREFIX}midiproc" buffer.c buffer.h main.c proto.h)
+ target_include_directories("${PROGRAM_PREFIX}midiproc"
+ PRIVATE "../src/" "${CMAKE_CURRENT_BINARY_DIR}/../")
+ target_link_libraries("${PROGRAM_PREFIX}midiproc" SDL2::SDL2main SDL2::mixer)
+endif()