Browse Source

Added find ctemplate cmake module, changed CMakeLists to use variables for linkage

Erik Winn 7 years ago
parent
commit
57bd815028
3 changed files with 84 additions and 9 deletions
  1. 8
    7
      CMakeLists.txt
  2. 70
    0
      cmake/FindCtemplate.cmake
  3. 6
    2
      src/CMakeLists.txt

+ 8
- 7
CMakeLists.txt View File

@@ -4,21 +4,22 @@ cmake_minimum_required(VERSION 2.6)
4 4
 
5 5
 set(CMAKE_VERBOSE_MAKEFILE ON)
6 6
 
7
-set(WORM_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src 
7
+set(WORM_INCLUDE_DIRS
8
+${CMAKE_SOURCE_DIR}/src 
8 9
 ${CMAKE_SOURCE_DIR}/src/sql
10
+${CMAKE_SOURCE_DIR}/src/orm
9 11
 ${CMAKE_SOURCE_DIR}/src/sql/drivers
10 12
 )
11 13
 
12
-#SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
13
-INCLUDE(cmake/FindMySQL.cmake)
14
-include(cmake/FindSqlite3.cmake)
15
-
16
-find_package(Boost)
14
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
15
+find_package(MySQL)
16
+find_package(Sqlite3)
17
+find_package(Ctemplate REQUIRED)
18
+find_package(Boost REQUIRED)
17 19
 
18 20
 #ADD_DEFINITIONS(-Wall -O2)
19 21
 ADD_DEFINITIONS(-Wall -g)
20 22
 
21
-
22 23
 include_directories( ${Boost_INCLUDE_DIRS} ${WORM_INCLUDE_DIRS} ${SQLITE3_INCLUDE_DIR})
23 24
 
24 25
 add_subdirectory(src)

+ 70
- 0
cmake/FindCtemplate.cmake View File

@@ -0,0 +1,70 @@
1
+# This module defines:
2
+# - CTEMPLATE_INCLUDE_DIR - Where to find Ctemplate header files (directory)
3
+# - CTEMPLATE_LIBRARIES - CTemplate libraries
4
+# - CTEMPLATE_LIBRARY_RELEASE - Where the release library is
5
+# - CTEMPLATE_LIBRARY_DEBUG - Where the debug library is
6
+# - CTEMPLATE_FOUND - Set to TRUE if we found everything
7
+#   (library, includes and executable)
8
+# Taking into account:
9
+# - CTEMPLATE_PREFIX
10
+#
11
+# Note: this only looks for the nothreads version for linking - alter to suit below..
12
+
13
+IF( CTEMPLATE_INCLUDE_DIR AND CTEMPLATE_LIBRARY_RELEASE AND CTEMPLATE_LIBRARY_DEBUG )
14
+    SET(CTEMPLATE_FIND_QUIETLY TRUE)
15
+ENDIF( CTEMPLATE_INCLUDE_DIR AND CTEMPLATE_LIBRARY_RELEASE AND CTEMPLATE_LIBRARY_DEBUG )
16
+
17
+FIND_PATH(CTEMPLATE_INCLUDE_DIR
18
+    template.h
19
+  PATHS
20
+    ${CTEMPLATE_PREFIX}/include
21
+    /usr/include/ctemplate
22
+    /usr/local/include/ctemplate
23
+)
24
+
25
+FIND_LIBRARY(CTEMPLATE_LIBRARY_RELEASE
26
+  NAMES
27
+    ctemplate_nothreads
28
+  PATHS
29
+    ${CTEMPLATE_PREFIX}/lib
30
+    /usr/lib
31
+    /usr/local/lib
32
+)
33
+
34
+FIND_LIBRARY(CTEMPLATE_LIBRARY_DEBUG
35
+  NAMES
36
+    ctemplate_nothreads
37
+)
38
+
39
+IF( CTEMPLATE_LIBRARY_RELEASE OR CTEMPLATE_LIBRARY_DEBUG AND CTEMPLATE_INCLUDE_DIR )
40
+    SET( CTEMPLATE_FOUND TRUE )
41
+ENDIF( CTEMPLATE_LIBRARY_RELEASE OR CTEMPLATE_LIBRARY_DEBUG AND CTEMPLATE_INCLUDE_DIR )
42
+
43
+IF( CTEMPLATE_LIBRARY_DEBUG AND CTEMPLATE_LIBRARY_RELEASE )
44
+    # if the generator supports configuration types then set
45
+    # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
46
+    IF( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
47
+        SET( CTEMPLATE_LIBRARIES optimized ${CTEMPLATE_LIBRARY_RELEASE} debug ${CTEMPLATE_LIBRARY_DEBUG} )
48
+    ELSE( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
49
+    # if there are no configuration types and CMAKE_BUILD_TYPE has no value
50
+    # then just use the release libraries
51
+        SET( CTEMPLATE_LIBRARIES ${CTEMPLATE_LIBRARY_RELEASE} )
52
+    ENDIF( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
53
+ELSEIF( CTEMPLATE_LIBRARY_RELEASE )
54
+    SET( CTEMPLATE_LIBRARIES ${CTEMPLATE_LIBRARY_RELEASE} )
55
+ELSE( CTEMPLATE_LIBRARY_DEBUG AND CTEMPLATE_LIBRARY_RELEASE )
56
+    SET( CTEMPLATE_LIBRARIES ${CTEMPLATE_LIBRARY_DEBUG} )
57
+ENDIF( CTEMPLATE_LIBRARY_DEBUG AND CTEMPLATE_LIBRARY_RELEASE )
58
+
59
+IF( CTEMPLATE_FOUND )
60
+    IF( NOT CTEMPLATE_FIND_QUIETLY )
61
+        MESSAGE( STATUS "Found ctemplate header file in ${CTEMPLATE_INCLUDE_DIR}")
62
+        MESSAGE( STATUS "Found ctemplate libraries: ${CTEMPLATE_LIBRARIES}")
63
+    ENDIF( NOT CTEMPLATE_FIND_QUIETLY )
64
+ELSE(CTEMPLATE_FOUND)
65
+    IF( CTEMPLATE_FIND_REQUIRED)
66
+        MESSAGE( FATAL_ERROR "Could not find ctemplate" )
67
+    ELSE( CTEMPLATE_FIND_REQUIRED)
68
+        MESSAGE( STATUS "Optional package ctemplate was not found" )
69
+    ENDIF( CTEMPLATE_FIND_REQUIRED)
70
+ENDIF(CTEMPLATE_FOUND)

+ 6
- 2
src/CMakeLists.txt View File

@@ -19,11 +19,15 @@ orm/wormcodetemplate.cpp
19 19
 orm/wormclassgenerator.cpp
20 20
 )
21 21
 
22
-add_library(worm ${LIBSRC})
22
+#switch these next two lines to build a shared library instead ..
23 23
 #add_library(worm SHARED ${LIBSRC})
24
-target_link_libraries(worm sqlite3 mysqlclient ctemplate_nothreads)
24
+add_library(worm ${LIBSRC})
25
+
26
+target_link_libraries(worm ${CTEMPLATE_LIBRARIES} ${SQLITE3_LIBRARIES} ${MYSQL_LIBRARIES} )
27
+
25 28
 add_executable(wormgen wormgen.cpp)
26 29
 target_link_libraries(wormgen worm)
30
+
27 31
 install(TARGETS wormgen worm 
28 32
             RUNTIME DESTINATION bin
29 33
             LIBRARY DESTINATION lib