some work on cmake_pascal files to better support flags we use, make engine compile as library again
--- a/cmake_modules/CMakePascalInformation.cmake Mon Jul 08 09:54:38 2013 +0200
+++ b/cmake_modules/CMakePascalInformation.cmake Mon Jul 08 12:10:55 2013 +0200
@@ -33,31 +33,34 @@
# so if these are not set just copy the flags from the c version
# No flags supported during linking as a shell script takes care of it
+# however to avoid interferences we escape -Wl flags to the Pascal -k
if(NOT CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS)
-#-dynamiclib -Wl,-headerpad_max_install_names for C
- set(CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
+#-shared
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
endif(NOT CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS)
-if(NOT CMAKE_SHARED_LIBRARY_Pascal_FLAGS)
- #another similarity, fpc: -fPIC Same as -Cg
- #(maybe required only for x86_64)
- set(CMAKE_SHARED_LIBRARY_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
-endif(NOT CMAKE_SHARED_LIBRARY_Pascal_FLAGS)
+if(NOT CMAKE_SHARED_LIBRARY_Pascal_FLAGS AND CMAKE_SHARED_LIBRARY_C_FLAGS)
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_LIBRARY_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
+endif()
+
+if(NOT CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS AND CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
+#-rdynamic
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
+endif()
-if(NOT CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS)
- set(CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
-endif(NOT CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS)
+if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG)
+#-Wl,-rpath,
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
+ string(REGEX REPLACE "," "" CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG})
+endif(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG)
-#if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG)
-# set(CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
-#endif(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG)
-
-#if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP)
-# set(CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
-#endif(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP)
+if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP)
+ set(CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
+endif(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP)
if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Pascal_FLAG)
- set(CMAKE_SHARED_LIBRARY_RPATH_LINK_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
+#-Wl,-rpath-link,
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_LIBRARY_RPATH_LINK_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
endif(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Pascal_FLAG)
# for most systems a module is the same as a shared library
@@ -70,12 +73,12 @@
# repeat for modules
if(NOT CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS)
- set(CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
endif(NOT CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS)
-if(NOT CMAKE_SHARED_MODULE_Pascal_FLAGS)
- set(CMAKE_SHARED_MODULE_Pascal_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
-endif(NOT CMAKE_SHARED_MODULE_Pascal_FLAGS)
+if(NOT CMAKE_SHARED_MODULE_Pascal_FLAGS AND CMAKE_SHARED_MODULE_C_FLAGS)
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_MODULE_Pascal_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
+endif()
if(NOT CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG)
set(CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG})
@@ -96,7 +99,7 @@
# Copy C version of this flag which is normally determined in platform file.
if(NOT CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG)
- set(CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
+ string(REGEX REPLACE "-Wl," "-k" CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
endif(NOT CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG)
set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.")
@@ -161,16 +164,25 @@
if(UNIX)
#when you have multiple ld installation make sure you get the one bundled with the system C compiler
include(Platform/${CMAKE_SYSTEM_NAME}-GNU-C.cmake OPTIONAL)
- if(CMAKE_C_COMPILER)
+ if(CMAKE_COMPILER_IS_GNUCC)
get_filename_component(CMAKE_C_COMPILER_DIR ${CMAKE_C_COMPILER} PATH)
set(CMAKE_Pascal_UNIX_FLAGS "-FD${CMAKE_C_COMPILER_DIR}")
- endif(CMAKE_C_COMPILER)
+ endif(CMAKE_COMPILER_IS_GNUCC)
if(APPLE)
- #add user framework directory
- set(CMAKE_Pascal_UNIX_FLAGS "-Ff~/Library/Frameworks ${CMAKE_Pascal_UNIX_FLAGS}")
+ #TODO: take care of CMAKE_INSTALL_NAME_DIR for shared targets
+ else(APPLE)
+ if(CMAKE_INSTALL_RPATH)
+ #need to escape twice because we use a script to link
+ #\\\\ is just \\ which escapes '\' in the final script
+ #same for $$ which escapes '$' in cmake
+ string(REGEX REPLACE "\\$" "\\\\$$" CMAKE_INSTALL_RPATH_ESCAPED ${CMAKE_INSTALL_RPATH})
+ #normally this flag is found in <LINK_LIBRARIES> but that's not active here
+ set(CMAKE_Pascal_UNIX_FLAGS "${CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG} -k'${CMAKE_INSTALL_RPATH_ESCAPED}' ${CMAKE_Pascal_UNIX_FLAGS}")
+ endif()
endif(APPLE)
endif(UNIX)
+ #-Cn is mandatory as it's what creates the ppas.* script
set(CMAKE_Pascal_COMPILE_OBJECT
"<CMAKE_Pascal_COMPILER> -Cn -FE${EXECUTABLE_OUTPUT_PATH} -FU${CMAKE_CURRENT_BINARY_DIR}/<OBJECT_DIR> ${CMAKE_Pascal_UNIX_FLAGS} <FLAGS> <SOURCE>")
endif(NOT CMAKE_Pascal_COMPILE_OBJECT)
--- a/cmake_modules/compilerchecks.cmake Mon Jul 08 09:54:38 2013 +0200
+++ b/cmake_modules/compilerchecks.cmake Mon Jul 08 12:10:55 2013 +0200
@@ -20,9 +20,6 @@
if(HAVE_STACKPROTECTOR)
add_flag_append(CMAKE_C_FLAGS "-fstack-protector-all -fstack-protector")
add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector-all -fstack-protector")
- add_flag_append(CMAKE_EXE_LINKER_FLAGS "-fstack-protector-all -fstack-protector")
- add_flag_append(CMAKE_SHARED_LIBRARY_C_FLAGS "-fstack-protector-all -fstack-protector")
- add_flag_append(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fstack-protector-all -fstack-protector")
endif()
endif()
@@ -43,6 +40,13 @@
add_linker_flag("-znoexecstack")
endif()
+ #check for origin on ELF, BSD $ORIGIN support
+ set(CMAKE_REQUIRED_FLAGS "-Wl,-zorigin")
+ check_c_compiler_flag("" HAVE_ORIGIN)
+ if(HAVE_ORIGIN)
+ add_linker_flag("-zorigin")
+ endif()
+
#check for full relro on ELF, Debian security
set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow")
check_c_compiler_flag("" HAVE_RELROFULL)
--- a/cmake_modules/paths.cmake Mon Jul 08 09:54:38 2013 +0200
+++ b/cmake_modules/paths.cmake Mon Jul 08 12:10:55 2013 +0200
@@ -51,29 +51,16 @@
#it's safe to use our RPATH because it is relative
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+#add the automatically determined parts of the RPATH
+#which point to directories outside the build tree to the install RPATH
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
+
#paths where to find libraries (final slash not optional):
# - the first is relative to the executable
# - the second is the same directory of the executable (so it runs in bin/)
# - the third one is the full path of the system dir
#source http://www.cmake.org/pipermail/cmake/2008-January/019290.html
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${target_library_install_dir}/:$ORIGIN/:${CMAKE_INSTALL_PREFIX}/${target_library_install_dir}/")
-#\\\\ is just \\ which escapes '\' in the final script; same for $$ which escapes '$' in cmake
-set(CMAKE_INSTALL_RPATH_ESCAPED "\\\\$$ORIGIN/../${target_library_install_dir}/:\\\\$$ORIGIN/:${CMAKE_INSTALL_PREFIX}/${target_library_install_dir}/")
-
-if(UNIX AND NOT APPLE)
- if(CMAKE_COMPILER_IS_GNUCC)
- #make sure $ORIGIN is respected
- add_linker_flag("-zorigin")
- endif()
- #apply RPATH settings to pascal executables
- add_flag_append(CMAKE_Pascal_FLAGS "-k-rpath -k'${CMAKE_INSTALL_RPATH_ESCAPED}'")
- #until we link with external things there is no need to set rpath on haskell
- #list(APPEND haskell_flags "-optl" "-Wl,-rpath,'${CMAKE_INSTALL_RPATH_ESCAPED}'")
-endif()
-
-#add the automatically determined parts of the RPATH
-#which point to directories outside the build tree to the install RPATH
-set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
#install_name_tool magic for OS X
--- a/cmake_modules/platform.cmake Mon Jul 08 09:54:38 2013 +0200
+++ b/cmake_modules/platform.cmake Mon Jul 08 12:10:55 2013 +0200
@@ -89,6 +89,9 @@
add_flag_append(CMAKE_Pascal_FLAGS "-XR${CMAKE_OSX_SYSROOT}")
add_flag_append(CMAKE_Pascal_FLAGS "-k-macosx_version_min -k${minimum_macosx_version}")
endif()
+
+ #add user framework directory
+ add_flag_append(CMAKE_Pascal_FLAGS "-Ff~/Library/Frameworks")
endif(APPLE)
if(MINGW)
--- a/cmake_modules/utils.cmake Mon Jul 08 09:54:38 2013 +0200
+++ b/cmake_modules/utils.cmake Mon Jul 08 12:10:55 2013 +0200
@@ -37,10 +37,14 @@
macro(add_linker_flag _FLAG)
list(APPEND haskell_flags "-optl" "-Wl,${_FLAG}")
- add_flag_append(CMAKE_Pascal_FLAGS "-k${_FLAG}")
- add_flag_append(CMAKE_EXE_LINKER_FLAGS "-Wl,${_FLAG}")
+ #executables
+ add_flag_append(CMAKE_C_LINK_FLAGS "-Wl,${_FLAG}")
+ add_flag_append(CMAKE_CXX_LINK_FLAGS "-Wl,${_FLAG}")
+ add_flag_append(CMAKE_Pascal_LINK_FLAGS "-k${_FLAG}")
+ #libraries
add_flag_append(CMAKE_SHARED_LIBRARY_C_FLAGS "-Wl,${_FLAG}")
add_flag_append(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-Wl,${_FLAG}")
+ #CMAKE_SHARED_LIBRARY_Pascal_FLAGS is already set by CMAKE_Pascal_LINK_FLAGS
endmacro(add_linker_flag _FLAG)
#TODO: find_package_or_bundle
--- a/hedgewars/CMakeLists.txt Mon Jul 08 09:54:38 2013 +0200
+++ b/hedgewars/CMakeLists.txt Mon Jul 08 12:10:55 2013 +0200
@@ -163,7 +163,7 @@
#SOURCE AND PROGRAMS SECTION
if(BUILD_ENGINE_LIBRARY)
- message(${WARNING} "Engine will be built as library (experimental)")
+ message("***Engine will be built as library (experimental)***")
if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
# due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits")