Преглед изворни кода

Modernise CMake

* Use `GNUInstallDirs` as it allows changing
  of all dirs in a standardised, Kitware
  supported way. `LIB_SUFFIX` is not idiomatic
  and not supported by Kitware:

    http://kwwidgets.org/Bug/view.php?id=10287

* Use ISO C++11 over the GNU variant, as this
  makes cross-platform porting efforts easier
  to other compilers.
* Don't search for a C compiler, speeds up
  configure step.
* Use proper idiom to change `CMAKE_INSTALL_PREFIX`
  default:

    https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
David Seifert пре 7 година
родитељ
комит
5a299816f0
1 измењених фајлова са 13 додато и 19 уклоњено
  1. 13
    19
      CMakeLists.txt

+ 13
- 19
CMakeLists.txt Прегледај датотеку

@@ -1,11 +1,15 @@
1 1
 cmake_minimum_required(VERSION 3.1.3)
2 2
 
3
+project(slop VERSION 7.3.49 LANGUAGES CXX)
4
+
3 5
 set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)")
4 6
 
5
-if ( NOT CMAKE_INSTALL_PREFIX )
6
-    set(CMAKE_INSTALL_PREFIX "/usr")
7
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
8
+  set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE)
7 9
 endif()
8 10
 
11
+include(GNUInstallDirs)
12
+
9 13
 # This should really never be disabled. The pure-X mode of slop is very expensive and buggy.
10 14
 # It also doesn't work on Wayland. Though if a system is never running a compositor, or
11 15
 # doesn't have OpenGL, this could remove some linking dependencies I suppose.
@@ -14,12 +18,8 @@ if ( SLOP_OPENGL )
14 18
   add_definitions(-DSLOP_OPENGL="True")
15 19
 endif()
16 20
 
17
-project(slop)
18
-
19 21
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
20 22
 
21
-set( CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Directory where man pages reside. (/usr/share/man, /usr/local/share/man, etc.)" )
22
-
23 23
 set( CMAKE_COMPRESS_MAN TRUE CACHE BOOL "Whether or not to compress the man pages for install." )
24 24
 
25 25
 if ( CMAKE_COMPRESS_MAN )
@@ -30,7 +30,7 @@ endif()
30 30
 
31 31
 include_directories("${PROJECT_BINARY_DIR}")
32 32
 
33
-add_definitions(-DSLOP_VERSION="v7.3.49")
33
+add_definitions(-DSLOP_VERSION="v${PROJECT_VERSION}")
34 34
 
35 35
 # The names have to be unique unfortunately.
36 36
 set(EXECUTABLE_NAME "slop")
@@ -63,11 +63,13 @@ endif()
63 63
 
64 64
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
65 65
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD 11)
66
+set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_EXTENSIONS OFF)
66 67
 
67 68
 add_executable(${EXECUTABLE_NAME} src/main.cpp)
68 69
 
69 70
 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
70 71
 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 11)
72
+set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_EXTENSIONS OFF)
71 73
 
72 74
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules" )
73 75
 
@@ -118,15 +120,7 @@ else()
118 120
   endif()
119 121
 endif()
120 122
 
121
-get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
122
-
123
-if ("${LIB64}" STREQUAL "TRUE")
124
-  set(LIBSUFFIX 64)
125
-else()
126
-  set(LIBSUFFIX "")
127
-endif()
128
-
129
-install( TARGETS ${EXECUTABLE_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
130
-install( TARGETS ${LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIBSUFFIX}" )
131
-install( FILES ${CMAKE_SOURCE_DIR}/src/slop.hpp DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT development )
132
-install( FILES "${CMAKE_SOURCE_DIR}/${MANTARGET}" DESTINATION  "${CMAKE_INSTALL_MANDIR}/man1" COMPONENT doc )
123
+install( TARGETS ${EXECUTABLE_NAME} DESTINATION "${CMAKE_INSTALL_BINDIR}" )
124
+install( TARGETS ${LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}" )
125
+install( FILES ${CMAKE_SOURCE_DIR}/src/slop.hpp DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT development )
126
+install( FILES "${CMAKE_SOURCE_DIR}/${MANTARGET}" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1" COMPONENT doc )