Browse Source

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 years ago
parent
commit
5a299816f0
1 changed files with 13 additions and 19 deletions
  1. 13
    19
      CMakeLists.txt

+ 13
- 19
CMakeLists.txt View File

1
 cmake_minimum_required(VERSION 3.1.3)
1
 cmake_minimum_required(VERSION 3.1.3)
2
 
2
 
3
+project(slop VERSION 7.3.49 LANGUAGES CXX)
4
+
3
 set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)")
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
 endif()
9
 endif()
8
 
10
 
11
+include(GNUInstallDirs)
12
+
9
 # This should really never be disabled. The pure-X mode of slop is very expensive and buggy.
13
 # This should really never be disabled. The pure-X mode of slop is very expensive and buggy.
10
 # It also doesn't work on Wayland. Though if a system is never running a compositor, or
14
 # It also doesn't work on Wayland. Though if a system is never running a compositor, or
11
 # doesn't have OpenGL, this could remove some linking dependencies I suppose.
15
 # doesn't have OpenGL, this could remove some linking dependencies I suppose.
14
   add_definitions(-DSLOP_OPENGL="True")
18
   add_definitions(-DSLOP_OPENGL="True")
15
 endif()
19
 endif()
16
 
20
 
17
-project(slop)
18
-
19
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
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
 set( CMAKE_COMPRESS_MAN TRUE CACHE BOOL "Whether or not to compress the man pages for install." )
23
 set( CMAKE_COMPRESS_MAN TRUE CACHE BOOL "Whether or not to compress the man pages for install." )
24
 
24
 
25
 if ( CMAKE_COMPRESS_MAN )
25
 if ( CMAKE_COMPRESS_MAN )
30
 
30
 
31
 include_directories("${PROJECT_BINARY_DIR}")
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
 # The names have to be unique unfortunately.
35
 # The names have to be unique unfortunately.
36
 set(EXECUTABLE_NAME "slop")
36
 set(EXECUTABLE_NAME "slop")
63
 
63
 
64
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
64
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
65
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD 11)
65
 set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD 11)
66
+set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_EXTENSIONS OFF)
66
 
67
 
67
 add_executable(${EXECUTABLE_NAME} src/main.cpp)
68
 add_executable(${EXECUTABLE_NAME} src/main.cpp)
68
 
69
 
69
 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
70
 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
70
 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 11)
71
 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 11)
72
+set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_EXTENSIONS OFF)
71
 
73
 
72
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules" )
74
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules" )
73
 
75
 
118
   endif()
120
   endif()
119
 endif()
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 )